Compartir a través de


ShapeCollection.IndexOf (Método)

Recupera el índice del Shape especificado en ShapeCollection.

Espacio de nombres:  Microsoft.VisualBasic.PowerPacks
Ensamblado:  Microsoft.VisualBasic.PowerPacks.Vs (en Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintaxis

'Declaración
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

Parámetros

Valor devuelto

Tipo: Int32
Valor de índice de base cero que representa la posición del Shape especificado en la colección ShapeCollection.

Comentarios

Si la forma no se encuentra en la colección, el valor devuelto del método de IndexOf es -1.

Ejemplos

El ejemplo de código siguiente muestra cómo utilizar el método de IndexOf para recuperar la ubicación de Shape en ShapeCollection. Este ejemplo requiere que tenga al menos dos controles de OvalShape en un formulario.

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

Seguridad de .NET Framework

Vea también

Referencia

ShapeCollection Clase

Microsoft.VisualBasic.PowerPacks (Espacio de nombres)

GetChildIndex

Otros recursos

Introducción a los controles de líneas y formas (Visual Studio)

Cómo: Dibujar líneas con el control LineShape (Visual Studio)

Cómo: Dibujar formas con los controles OvalShape y RectangleShape (Visual Studio)