ControlCollection.IndexOf Method (Object) (2007 System)

Searches for the specified control and returns the zero-based index of the first occurrence in the ControlCollection instance.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Function IndexOf ( _
    control As Object _
) As Integer
'Usage
Dim instance As ControlCollection 
Dim control As Object 
Dim returnValue As Integer 

returnValue = instance.IndexOf(control)
public int IndexOf(
    Object control
)
public:
int IndexOf(
    Object^ control
)
public function IndexOf(
    control : Object
) : int

Parameters

Return Value

Type: System.Int32
The index of the control, or -1 if the control is not in the ControlCollection instance.

Examples

The following code example adds a Button control to the top of the worksheet, and then displays the index of the button in a message box.

Private Sub ExcelControlIndexOf()

    Dim Button1 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        0, 0, 56.25, 17.25, "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 ExcelControlIndexOf()
{

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(0, 0, 56.25, 17.25,
        "button1");
    button1.Text = "OK";

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

.NET Framework Security

See Also

Reference

ControlCollection Class

ControlCollection Members

IndexOf Overload

Microsoft.Office.Tools.Excel Namespace