ShapeCollection.IndexOf 方法
擷取指定的索引Shape在ShapeCollection。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
Public Function IndexOf ( _
value As Shape _
) As Integer
public int IndexOf(
Shape value
)
public:
int IndexOf(
Shape^ value
)
member IndexOf :
value:Shape -> int
public function IndexOf(
value : Shape
) : int
參數
- value
型別:Microsoft.VisualBasic.PowerPacks.Shape
要在集合中尋找的 Shape。
傳回值
型別:System.Int32
以零起始的索引值,表示指定的 Shape 在 ShapeCollection 中的位置。
備註
如果在集合中,找不到圖形IndexOf方法會傳回值為-1。
範例
下列程式碼範例示範如何使用IndexOf方法,以擷取的位置Shape在ShapeCollection。這個範例要求您必須至少兩個OvalShape在表單上的控制項。
Private Sub OvalShape2_Click() Handles OvalShape2.Click
Dim i As Integer
' Find the index for OvalShape1.
i = OvalShape2.Parent.Shapes.IndexOf(OvalShape1)
' If the shape is not in the collection, display a message.
If i = -1 Then
MsgBox("OvalShape1 is not in this collection.")
End If
End Sub
private void ovalShape2_Click(System.Object sender, System.EventArgs e)
{
int i;
// Find the index for OvalShape1.
i = ovalShape2.Parent.Shapes.IndexOf(ovalShape1);
// If the shape is not in the collection, display a message.
if (i == -1)
{
MessageBox.Show("ovalShape1 is not in this collection.");
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
Line 和 Shape 控制項簡介 (Visual Studio)
HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)
HOW TO:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)