Share via


ControlCollection.Contains, méthode (Object)

Détermine si le contrôle spécifié est membre de l'instance de ControlCollection.

Espace de noms :  Microsoft.Office.Tools.Excel
Assembly :  Microsoft.Office.Tools.Excel (dans Microsoft.Office.Tools.Excel.dll)

Syntaxe

'Déclaration
Function Contains ( _
    control As Object _
) As Boolean
bool Contains(
    Object control
)

Paramètres

Valeur de retour

Type : System.Boolean
true si le contrôle a été trouvé dans la collection ; sinon, false.

Exemples

L'exemple de code suivant ajoute un contrôle Button en haut de la feuille de calcul, puis affiche l'index du bouton dans un message.

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

Sécurité .NET Framework

Voir aussi

Référence

ControlCollection Interface

Contains, surcharge

Microsoft.Office.Tools.Excel, espace de noms