共用方式為


ShapeCollection.ContainsKey 方法

判斷 ShapeCollection 是否包含具有指定索引鍵的項目。

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

語法

'宣告
Public Function ContainsKey ( _
    key As String _
) As Boolean
public bool ContainsKey(
    string key
)
public:
bool ContainsKey(
    String^ key
)
member ContainsKey : 
        key:string -> bool
public function ContainsKey(
    key : String
) : boolean

參數

傳回值

類型:Boolean
如果 ShapeCollection 包含具有指定索引鍵的項目,則為 true,否則為 false。

備註

ShapeName 屬性等於 Shape 的索引鍵的 ShapeCollection

範例

如果是表單之 ShapeCollection的成員,下列範例示範如何使用 ContainsKey 方法從表單中移除 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.ContainsKey("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.ContainsKey("ovalShape2"))
    {
        canvas.Shapes.Remove(ovalShape2);
    }
}

.NET Framework 安全性

請參閱

參考

ShapeCollection 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

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

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

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