共用方式為


ShapeContainer.Shapes 屬性

取得包含在 ShapeContainer 中的圖案集合。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
<BrowsableAttribute(False)> _
Public ReadOnly Property Shapes As ShapeCollection
[BrowsableAttribute(false)]
public ShapeCollection Shapes { get; }
[BrowsableAttribute(false)]
public:
property ShapeCollection^ Shapes {
    ShapeCollection^ get ();
}
[<BrowsableAttribute(false)>]
member Shapes : ShapeCollection with get
function get Shapes () : ShapeCollection

屬性值

類型:Microsoft.VisualBasic.PowerPacks.ShapeCollection
ShapeCollection ,表示 ShapeContainer 中所包含之圖案的集合。

備註

ShapeCollection 為父代圖案的集合。 例如,在中,當多個圖案加入至 Form時,每個圖案是由 ShapeCollection 所指定的成員為表單的 ShapeContainer

您可以在 ShapeCollection 指定的圖案搭配使用到 ShapeContainer 使用方法可用的 ShapeCollection 類別。

當您加入數個形狀到 ShapeContainer時,我們建議您在初始化要加入的圖案之前呼叫 SuspendLayout 方法。 在您將圖形加入至 ShapeContainer之後,呼叫 ResumeLayout 方法。 使用 SuspendLayoutResumeLayout 會將有許多圖形應用程式的效能。

範例

下列範例會從表單的 ShapeCollection 移除 Shape (由 Shapes 屬性表示)),如果它是集合的成員。 這個範例要求您具有 LineShapeOvalShapeRectangleShape 控制項在表單中。 按下形狀時,會從 ShapeCollection 中移除,除非是在集合的最後一個圖案。

Private Sub Shapes_Click(
    ByVal sender As System.Object, 
    ByVal e As System.EventArgs
  ) Handles RectangleShape1.Click, 
            OvalShape1.Click, LineShape1.Click

    ' Determine whether the shape is in the collection. 
    If ShapeContainer1.Shapes.Contains(sender) Then 
        ' If the index is greater than 0, remove the shape. 
        If ShapeContainer1.Shapes.IndexOf(sender) > 0 Then
            ShapeContainer1.Shapes.Remove(sender)
        End If 
    End If 
End Sub
private void Shapes_Click(System.Object sender, System.EventArgs e)
{
    // Determine whether the shape is in the collection. 
    if (shapeContainer1.Shapes.Contains((Shape) sender))
    // If the index is greater than 0, remove the shape.
    {
        if (shapeContainer1.Shapes.IndexOf((Shape)sender) > 0)
        {
            shapeContainer1.Shapes.Remove((Shape)sender);
        }
    }
}

.NET Framework 安全性

請參閱

參考

ShapeContainer 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

Line 和 Shape 控制項簡介 (Visual Studio)

如何:使用 LineShape 控制項繪製線條 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)