Share via


ShapeCollection.IndexOf 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 IndexOf(
    Shape value
)
public:
int IndexOf(
    Shape^ value
)
member IndexOf : 
        value:Shape -> int
Public Function IndexOf (
    value As Shape
) As Integer

Parameters

Return Value

Type: System.Int32

A zero-based index value that represents the position of the specified Shape in the ShapeCollection.

Remarks

If the shape is not found in the collection, the IndexOf method return value is -1.

Examples

The following code example demonstrates how to use the IndexOf method to retrieve the location of a Shape in the 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;
    // 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.");
    }
}
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

See Also

GetChildIndex
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