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
參數
key
類型:String要在 ShapeCollection 中尋找的索引鍵。
傳回值
類型:Boolean
如果 ShapeCollection 包含具有指定索引鍵的項目,則為 true,否則為 false。
備註
Shape 的 Name 屬性等於 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
Line 和 Shape 控制項簡介 (Visual Studio)