ShapeCollection.IndexOfKey 方法
擷取集合中指定之項目第一次出現時的所在索引。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
Public Function IndexOfKey ( _
key As String _
) As Integer
public int IndexOfKey(
string key
)
public:
int IndexOfKey(
String^ key
)
member IndexOfKey :
key:string -> int
public function IndexOfKey(
key : String
) : int
參數
key
類型:String要搜尋的圖案的名稱。
傳回值
類型:Int32
具有指定名稱之圖案在集合中第一次出現的以零起始的索引。
備註
索引鍵比較不區分大小寫。 如果 key 參數是 Null 參考 (在 Visual Basic 中為Nothing ) 或空字串,或具有指定索引鍵的項目是找不到, IndexOfKey 會傳回 -1。
Shape 的 Name 屬性等於 Shape 的索引鍵的 ShapeCollection。
範例
下列程式碼範例示範如何使用 IndexOfKey 方法擷取 Shape 位置的 ShapeCollection。 這個範例要求您的表單上必須有至少兩個 OvalShape 控制項。
Private Sub OvalShape1_Click() Handles OvalShape1.Click
Dim i As Integer
' Find the index for OvalShape1.
i = OvalShape1.Parent.Shapes.IndexOfKey("OvalShape2")
' If the shape is not in the collection, display a message.
If i = -1 Then
MsgBox("OvalShape2 is not in this collection.")
End If
End Sub
private void ovalShape1_Click(System.Object sender, System.EventArgs e)
{
int i;
// Find the index for OvalShape1.
i = ovalShape1.Parent.Shapes.IndexOfKey("ovalShape2");
// If the shape is not in the collection, display a message.
if (i == -1)
{
MessageBox.Show("ovalShape2 is not in this collection.");
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
Line 和 Shape 控制項簡介 (Visual Studio)