Udostępnij za pośrednictwem


Metoda ControlCollection.IndexOf — (Object)

Wyszukuje określony formant i zwraca wartość indeksu pierwszego wystąpienia w ControlCollection wystąpienie.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestaw:  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Function IndexOf ( _
    control As Object _
) As Integer
int IndexOf(
    Object control
)

Parametry

Wartość zwracana

Typ: System.Int32
Indeks kontroli, lub -1, jeśli formant nie znajduje się w ControlCollection wystąpienie.

Przykłady

Poniższy kod dodaje Button kontroli do początku dokumentu, a następnie wyświetla indeks przycisk w oknie komunikatu.

Private Sub WordControlIndexOf()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Button1 As Microsoft.Office.Tools.Word.Controls.Button _
        = Me.Controls.AddButton(0, 0, 56.25F, 17.25F, "Button1")
    Button1.Text = "OK"

    If Me.Controls.Contains(Button1) Then
        MessageBox.Show("The index of Button1 is " _
        & Controls.IndexOf(Button1))
    End If
End Sub 
private void WordControlIndexOf()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.Button button1 =
        this.Controls.AddButton(0, 0, 56.25F, 17.25F,
        "button1");
    button1.Text = "OK";

    if (this.Controls.Contains(button1))
    {
        MessageBox.Show("The index of button1 is " + 
            Controls.IndexOf(button1));
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ControlCollection Interfejs

Przeciążenie IndexOf

Przestrzeń nazw Microsoft.Office.Tools.Word