共用方式為


ShapeCollection.GetChildIndex 方法 (Shape, Boolean)

擷取指定的索引ShapeShapeCollection,並選擇性地引發例外狀況,如果指定的Shape並不在ShapeCollection

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

語法

'宣告
Public Function GetChildIndex ( _
    child As Shape, _
    throwException As Boolean _
) As Integer
public int GetChildIndex(
    Shape child,
    bool throwException
)
public:
int GetChildIndex(
    Shape^ child, 
    bool throwException
)
member GetChildIndex : 
        child:Shape * 
        throwException:bool -> int 
public function GetChildIndex(
    child : Shape, 
    throwException : boolean
) : int

參數

  • throwException
    型別:System.Boolean
    true 表示如果 child 參數中指定的 Shape 不是 ShapeCollection 中的控制項,則擲回例外狀況,否則為 false。

傳回值

型別:System.Int32
以零起始的索引值,表示指定的位置ShapeShapeCollection。或-1 是否指定Shape中找不到ShapeCollection

例外狀況

例外狀況 條件
ArgumentException

child圖形並不在ShapeCollection和throwException參數值是true。

備註

索引表示形狀加入至集合的順序。如果要從集合移除形狀,會重新指派形狀的索引。

只有當 throwException 參數是 false 時,才會傳回 -1 的值。

範例

下列程式碼範例示範如何使用GetChildIndex方法,以擷取的位置ShapeShapeCollection。這個範例要求您必須至少兩個OvalShape在表單上的控制項。

Private Sub OvalShape1_Click() Handles OvalShape1.Click
    Dim i As Integer
    ' Find the index for OvalShape1.
    i = OvalShape1.Parent.Shapes.GetChildIndex(OvalShape2, False)
    ' If the shape is not in the collection, display a message.
    If i = -1 Then
        MsgBox("OvalShape2 is not in this collection.")
    Else
        MsgBox("The index for OvalShape2 is " & CStr(i))
    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.GetChildIndex(ovalShape2, false);
    // If the shape is not in the collection, display a message.
    if (i==-1)
    {
        MessageBox.Show("ovalShape2 is not in this collection.");
    }
    else
    {
        String index;
        index = i.ToString();
        MessageBox.Show("The index for ovalShape2 is " + index);
    }
}

.NET Framework 安全性

請參閱

參考

ShapeCollection 類別

GetChildIndex 多載

Microsoft.VisualBasic.PowerPacks 命名空間

IndexOf

其他資源

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

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

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