Método ShapeCollection.GetChildIndex (Shape, Boolean)

Recupera o índice especificado Shape na ShapeCollectione, opcionalmente, gera uma exceção, se especificado Shape não estiver a ShapeCollection.

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

Sintaxe

'Declaração
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: System.Boolean
    true Lançar uma exceção se a Shape especificado na child parâmetro não é um controle no ShapeCollection; Caso contrário, false.

Valor de retorno

Tipo: System.Int32
Um valor de índice baseado em zero que representa o local especificado Shape na ShapeCollection.Ou -1 se o especificado Shape não for encontrado na ShapeCollection.

Exceções

Exceção Condição
ArgumentException

O child forma não estiver a ShapeCollection e o throwException o valor do parâmetro é true.

Comentários

O índice representa a ordem na qual as formas foram adicionadas à coleção.Se as formas forem removidas da coleção, os índices das formas são reatribuídos.

Um valor de retorno-1 é retornado somente quando o throwException parâmetro é false.

Exemplos

O exemplo de código a seguir demonstra como usar o GetChildIndex método para recuperar o local de um Shape em um ShapeCollection.Este exemplo requer que você tenha pelo menos duas OvalShape controles em um formulário.

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

Segurança do .NET Framework

Consulte também

Referência

ShapeCollection Classe

Sobrecargas GetChildIndex

Namespace Microsoft.VisualBasic.PowerPacks

IndexOf

Outros recursos

Introdução à linha e controles Shape (Visual Studio)

Como: desenhar linhas com o controle de LineShape (Visual Studio)

Como: desenhar formas com os controles de RectangleShape (Visual Studio) e o OvalShape