ShapeCollection.IndexOf Method

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
)

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.");
    }
}

.NET Framework Security

See Also

Reference

ShapeCollection Class

Microsoft.VisualBasic.PowerPacks Namespace

GetChildIndex

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)