ShapeCollection.IndexOfKey Method (String)
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
public int IndexOfKey(
string key
)
public:
int IndexOfKey(
String^ key
)
member IndexOfKey :
key:string -> int
Public Function IndexOfKey (
key As String
) As Integer
Parameters
key
Type: System.StringThe name of the shape to search for.
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 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.");
}
}
Private Sub OvalShape1_Click() 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
See Also
IndexOf
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