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
'Declaration
Public Function IndexOf ( _
value As Shape _
) As Integer
public int IndexOf(
Shape value
)
public:
int IndexOf(
Shape^ value
)
member IndexOf :
value:Shape -> int
public function IndexOf(
value : Shape
) : int
Parameters
value
Type: Microsoft.VisualBasic.PowerPacks.ShapeThe Shape to locate in the collection.
Return Value
Type: 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 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
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
- 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)