다음을 통해 공유


Button.Index 속성

시트의 OLEObjects 컬렉션에 있는 Button의 인덱스 번호를 가져옵니다.

네임스페이스:  Microsoft.Office.Tools.Excel.Controls
어셈블리:  Microsoft.Office.Tools.Excel.v4.0.Utilities(Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

구문

‘선언
Public ReadOnly Property Index As Integer
public int Index { get; }

속성 값

형식: System.Int32
시트의 OLEObjects 컬렉션에 있는 Button의 인덱스 번호입니다.

설명

Microsoft Office Excel 워크시트에 추가된 컨트롤의 인덱스는 시트의 OLEObjects 컬렉션에 대한 인덱스이므로 값이 2부터 시작합니다.

예제

다음 코드 예제에서는 워크시트에 세 개의 Button 컨트롤을 추가합니다.이러한 단추는 Index 속성을 사용하여 클릭된 단추의 인덱스를 표시하는 Click 이벤트 처리기를 공유합니다.

이 예제는 문서 수준 사용자 지정을 위한 것입니다.

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

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

Button 클래스

Microsoft.Office.Tools.Excel.Controls 네임스페이스