Freigeben über


ControlCollection.Contains Method

Definition

Determines whether the specified control is a member of the ControlCollection instance.

Overloads

Contains(String)

Determines whether a control with the specified name is a member of the ControlCollection instance.

Contains(Object)

Determines whether the specified control is a member of the ControlCollection instance.

Remarks

This method enables you to determine whether a control is a member of the collection before attempting to perform operations on the control. You can use this method to confirm that a control has been added to, or is still a member of, the ControlCollection instance.

Contains(String)

Determines whether a control with the specified name is a member of the ControlCollection instance.

public:
 bool Contains(System::String ^ name);
public bool Contains (string name);
abstract member Contains : string -> bool
Public Function Contains (name As String) As Boolean

Parameters

name
String

The name of the control you want to search for in the ControlCollection instance.

Returns

true if the control was found in the collection; otherwise, false.

Applies to

Contains(Object)

Determines whether the specified control is a member of the ControlCollection instance.

public:
 bool Contains(System::Object ^ control);
public bool Contains (object control);
abstract member Contains : obj -> bool
Public Function Contains (control As Object) As Boolean

Parameters

control
Object

The control that you want to search for in the ControlCollection instance.

Returns

true if the control was found in the collection; otherwise, false.

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