共用方式為


ShapeCollection.Contains 方法

判斷指定的 Shape 是否為集合的成員。

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

語法

'宣告
Public Function Contains ( _
    value As Shape _
) As Boolean
public bool Contains(
    Shape value
)
public:
bool Contains(
    Shape^ value
)
member Contains : 
        value:Shape -> bool
public function Contains(
    value : Shape
) : boolean

參數

傳回值

類型:Boolean
如果 Shape 是集合的成員,則為 true,否則為 false。

備註

這個方法可用來判斷 Shape 是否為集合的成員,在您嘗試對 Shape之前的作業。 可以使用這個方法來確定 Shape 已經加入集合或仍然是集合的成員。

範例

如果是表單之 ShapeCollection的成員,下列範例示範如何使用 Contains 方法從表單中移除 Shape 。 這個範例要求您的表單上必須有至少兩個 OvalShape 控制項。

    Private Sub Form1_Click() Handles Me.Click
        Dim canvas As ShapeContainer
        ' Get the ShapeContainer.
        canvas = OvalShape1.Parent
        ' If OvalShape2 is in the same collection, remove it. 
        If canvas.Shapes.Contains(OvalShape2) Then
            canvas.Shapes.Remove(OvalShape2)
        End If 
    End Sub
        private void form1_Click(object sender, System.EventArgs e)
        {
            ShapeContainer canvas;
            // Get the ShapeContainer.
            canvas = ovalShape1.Parent;
            // If OvalShape2 is in the same collection, remove it. 
            if (canvas.Shapes.Contains(ovalShape2))
            {
                canvas.Shapes.Remove(ovalShape2);
            }
        }

.NET Framework 安全性

請參閱

參考

ShapeCollection 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

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

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