共用方式為


ShapeCollection.IndexOf 方法

擷取指定的索引ShapeShapeCollection

命名空間:  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

參數

傳回值

型別:System.Int32
以零起始的索引值,表示指定的 ShapeShapeCollection 中的位置。

備註

如果在集合中,找不到圖形IndexOf方法會傳回值為-1。

範例

下列程式碼範例示範如何使用IndexOf方法,以擷取的位置ShapeShapeCollection。這個範例要求您必須至少兩個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 安全性

請參閱

參考

ShapeCollection 類別

Microsoft.VisualBasic.PowerPacks 命名空間

GetChildIndex

其他資源

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

HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)

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