ShapeCollection.GetChildIndex Method (Shape, Boolean)
Retrieves the index of the specified Shape in the ShapeCollection, and optionally raises an exception if the specified Shape is not in the ShapeCollection.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'Declaração
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
Parameters
- child
Type: Microsoft.VisualBasic.PowerPacks.Shape
The Shape to search for in the ShapeCollection.
- throwException
Type: System.Boolean
true to throw an exception if the Shape specified in the child parameter is not a control in the ShapeCollection; otherwise, false.
Return Value
Type: System.Int32
A zero-based index value that represents the location of the specified Shape in the ShapeCollection. Or -1 if the specified Shape is not found in the ShapeCollection.
Exceptions
Exception | Condition |
---|---|
ArgumentException | The child shape is not in the ShapeCollection and the throwException parameter value is true. |
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.
A return value of -1 is returned only when the throwException parameter is false.
Examples
The following code 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 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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualBasic.PowerPacks Namespace
Other Resources
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)