Compartir a través de


ShapeCollection.GetChildIndex (Método) (Shape, Boolean)

Recupera el índice del objeto Shape especificado en ShapeCollection y, opcionalmente, produce una excepción si el objeto Shape especificado no está en ShapeCollection.

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

Sintaxis

'Declaración
Public Function GetChildIndex ( _
    child As Shape, _
    throwException As Boolean _
) As Integer
public int GetChildIndex(
    Shape child,
    bool throwException
)
public:
int GetChildIndex(
    Shape^ child, 
    bool throwException
)
member GetChildIndex : 
        child:Shape * 
        throwException:bool -> int
public function GetChildIndex(
    child : Shape, 
    throwException : boolean
) : int

Parámetros

  • throwException
    Tipo: Boolean

    true para producir una excepción si el Shape especificado en el parámetro child no pertenece a la colección ShapeCollection; en caso contrario, es false.

Valor devuelto

Tipo: Int32
Valor de índice de base cero que representa la ubicación del Shape especificado en la colección ShapeCollection.O bien -1 si el Shape que se ha especificado no se encuentra en ShapeCollection.

Excepciones

Excepción Condición
ArgumentException

La forma child no está en ShapeCollection y el valor del parámetro throwException es true.

Comentarios

El índice representa el orden en que las formas se agregaron a la colección. Si las formas se quitan de la colección, los índices de las formas se reasignan.

Se devuelve el valor -1 sólo si el parámetro throwException es false.

Ejemplos

El ejemplo de código siguiente muestra cómo utilizar el método de GetChildIndex 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 OvalShape1_Click() Handles OvalShape1.Click
    Dim i As Integer 
    ' Find the index for OvalShape1.
    i = OvalShape1.Parent.Shapes.GetChildIndex(OvalShape2, False)
    ' If the shape is not in the collection, display a message. 
    If i = -1 Then
        MsgBox("OvalShape2 is not in this collection.")
    Else
        MsgBox("The index for OvalShape2 is " & CStr(i))
    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.GetChildIndex(ovalShape2, false);
    // If the shape is not in the collection, display a message. 
    if (i==-1)
    {
        MessageBox.Show("ovalShape2 is not in this collection.");
    }
    else
    {
        String index;
        index = i.ToString();
        MessageBox.Show("The index for ovalShape2 is " + index);
    }
}

Seguridad de .NET Framework

Vea también

Referencia

ShapeCollection Clase

GetChildIndex (Sobrecarga)

Microsoft.VisualBasic.PowerPacks (Espacio de nombres)

IndexOf

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)