ControlCollection.IndexOf Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
IndexOf(Object) |
Searches for the specified control and returns the zero-based index of the first occurrence in the ControlCollection instance. |
IndexOf(String) |
Searches for the first occurrence of a control with the specified name in the ControlCollection instance. |
IndexOf(Object)
Searches for the specified control and returns the zero-based index of the first occurrence in the ControlCollection instance.
public:
int IndexOf(System::Object ^ control);
public int IndexOf (object control);
abstract member IndexOf : obj -> int
Public Function IndexOf (control As Object) As Integer
Parameters
- control
- Object
The control to find the index of.
Returns
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 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));
}
}
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
Applies to
IndexOf(String)
Searches for the first occurrence of a control with the specified name in the ControlCollection instance.
public:
int IndexOf(System::String ^ name);
public int IndexOf (string name);
abstract member IndexOf : string -> int
Public Function IndexOf (name As String) As Integer
Parameters
- name
- String
The name of the control that you want to find the index of.
Returns
An integer that is the index of the control, or -1 if the control is not in the ControlCollection instance.