ShapeCollection.GetChildIndex Method (Shape)
Retrieves the index of the specified Shape in the ShapeCollection.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
public int GetChildIndex(
Shape child
)
public:
int GetChildIndex(
Shape^ child
)
member GetChildIndex :
child:Shape -> int
Public Function GetChildIndex (
child As Shape
) As Integer
Parameters
child
Type: Microsoft.VisualBasic.PowerPacks.ShapeThe Shape to search for in the ShapeCollection.
Return Value
Type: System.Int32
A zero-based index value that represents the location of the specified Shape in the ShapeCollection.
Exceptions
Exception | Condition |
---|---|
ArgumentException | The child shape is not in the ShapeCollection. |
Remarks
The index represents the order in which the shapes were added to the collection. If shapes are removed from the collection, the indexes of the shapes are reassigned.
Examples
The following example demonstrates how to use the GetChildIndex method to retrieve the location of a Shape in a ShapeCollection. This example requires that you have at least two OvalShape controls on a form.
private void ovalShape2_Click(System.Object sender, System.EventArgs e)
{
int i;
String index;
// Find the index for OvalShape1.
i = ovalShape2.Parent.Shapes.GetChildIndex(ovalShape1);
index = i.ToString();
MessageBox.Show("The index for OvalShape1 is " + index);
}
Private Sub OvalShape2_Click() Handles OvalShape2.Click
Dim i As Integer
' Find the index for OvalShape1.
i = OvalShape2.Parent.Shapes.GetChildIndex(OvalShape1)
MsgBox("The index for OvalShape1 is " & CStr(i))
End Sub
See Also
IndexOf
GetChildIndex Overload
ShapeCollection Class
Microsoft.VisualBasic.PowerPacks Namespace
Introduction to the Line and Shape Controls (Visual Studio)
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)
Return to top