共用方式為


ShapeCollection 類別

更新:2007 年 11 月

表示 Shape 物件的集合。

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

語法

Public NotInheritable Class ShapeCollection _
    Implements IList, IDisposable

Dim instance As ShapeCollection
public sealed class ShapeCollection : IList, 
    IDisposable
public ref class ShapeCollection sealed : IList, 
    IDisposable
public final class ShapeCollection implements IList, IDisposable

備註

AddRemoveRemoveAt 方法可以讓您加入和移除集合中的個別形狀。您也可以使用 AddRangeClear 方法,加入或移除集合中的所有形狀。

您可以將形狀傳遞至 Contains 方法,以判斷 Shape 是否為集合的成員。若要取得集合中形狀的位置索引值,請將形狀傳遞至 IndexOf 方法。您可以呼叫 CopyTo 方法,將集合複製到陣列。

範例

下列程式碼範例會從表單的 ShapeCollection 中移除 Shape (如果它是集合的成員)。此範例要求您的表單上必須有 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);
        }
    }
}

繼承階層架構

System.Object
  Microsoft.VisualBasic.PowerPacks.ShapeCollection

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

ShapeCollection 成員

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)

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