Share via


ShapeCollection.IndexOfKey Method

Retrieves the index of the first occurrence of the specified item in the collection.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
Public Function IndexOfKey ( _
    key As String _
) As Integer
'Usage
Dim instance As ShapeCollection 
Dim key As String 
Dim returnValue As Integer 

returnValue = instance.IndexOfKey(key)
public int IndexOfKey(
    string key
)
public:
int IndexOfKey(
    String^ key
)
public function IndexOfKey(
    key : String
) : int

Parameters

Return Value

Type: System.Int32
The zero-based index of the first occurrence of the shape that has the specified name in the collection.

Remarks

The key comparison is not case sensitive. If the key parameter is a null reference (Nothing in Visual Basic) or an empty string, or an item with the specified key is not found, IndexOfKey returns -1.

The Name property of a Shape is the same as the key for a Shape in the ShapeCollection.

Examples

The following code example demonstrates how to use the IndexOfKey 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 Sub OvalShape1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles OvalShape1.Click
    Dim i As Integer 
    ' Find the index for OvalShape1.
    i = OvalShape1.Parent.Shapes.IndexOfKey("OvalShape2")
    ' If the shape is not in the collection, display a message. 
    If i = -1 Then
        MsgBox("OvalShape2 is not in this collection.")
    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.IndexOfKey("ovalShape2");
    // If the shape is not in the collection, display a message. 
    if (i == -1)
    {
        MessageBox.Show("ovalShape2 is not in this collection.");
    }
}

.NET Framework Security

See Also

Reference

ShapeCollection Class

ShapeCollection Members

Microsoft.VisualBasic.PowerPacks Namespace

IndexOf

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)