Sdílet prostřednictvím


Button.Index – vlastnost

Získá číslo indexu Button v rámci kolekce OLEObjects na listu.

Obor názvů:  Microsoft.Office.Tools.Excel.Controls
Sestavení:  Microsoft.Office.Tools.Excel.v4.0.Utilities (v Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntaxe

'Deklarace
Public ReadOnly Property Index As Integer
public int Index { get; }

Hodnota vlastnosti

Typ: System.Int32
Indexové číslo Button v rámci kolekce OLEObjects na listu.

Poznámky

Hodnota indexu ovládacích prvků přidaných do sešitu aplikace Microsoft Office Excel začíná 2, protože index je OLEObjects kolekce list.

Příklady

Následující příklad kódu přidá tři Button ovládacích prvků na list.Tato tlačítka sdílet Click obslužnou rutinu události, která se používá Index vlastností zobrazení index tlačítka, na které bylo kliknuto.

Tento příklad je pro vlastní úpravy úrovni dokumentu.

Private Sub DisplayIndex()
    Dim IndexButton1 As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "IndexButton1")
    IndexButton1.Text = "Click to view the index"
    AddHandler IndexButton1.Click, AddressOf indexButton_Click

    Dim IndexButton2 As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B5", "C6"), "IndexButton2")
    IndexButton2.Text = "Click to view the index"
    AddHandler IndexButton2.Click, AddressOf indexButton_Click

    Dim IndexButton3 As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B8", "C9"), "IndexButton3")
    IndexButton3.Text = "Click to view the index"
    AddHandler IndexButton3.Click, AddressOf indexButton_Click
End Sub

Private Sub IndexButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ClickedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        CType(sender, Microsoft.Office.Tools.Excel.Controls.Button)

    MsgBox("The index is " & ClickedButton.Index.ToString())
End Sub
private void DisplayIndex()
{
    Microsoft.Office.Tools.Excel.Controls.Button indexButton1 =
            this.Controls.AddButton(this.Range["B2", "C3"],
            "indexButton1");
    indexButton1.Text = "Click to view the index";
    indexButton1.Click += new EventHandler(indexButton_Click);

    Microsoft.Office.Tools.Excel.Controls.Button indexButton2 =
            this.Controls.AddButton(this.Range["B5", "C6"],
            "indexButton2");
    indexButton2.Text = "Click to view the index";
    indexButton2.Click += new EventHandler(indexButton_Click);

    Microsoft.Office.Tools.Excel.Controls.Button indexButton3 =
            this.Controls.AddButton(this.Range["B8", "C9"],
            "indexButton3");
    indexButton3.Text = "Click to view the index";
    indexButton3.Click += new EventHandler(indexButton_Click);
}

void indexButton_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Excel.Controls.Button)sender;

    MessageBox.Show("The index is " +
        clickedButton.Index.ToString());
}

Zabezpečení rozhraní .NET Framework

Viz také

Referenční dokumentace

Button Třída

Microsoft.Office.Tools.Excel.Controls – obor názvů