Control.ControlCollection.Contains(Control) Yöntem

Tanım

Belirtilen denetimin koleksiyonun bir üyesi olup olmadığını belirler.

public:
 bool Contains(System::Windows::Forms::Control ^ control);
public bool Contains(System.Windows.Forms.Control control);
public bool Contains(System.Windows.Forms.Control? control);
member this.Contains : System.Windows.Forms.Control -> bool
Public Function Contains (control As Control) As Boolean

Parametreler

control
Control

Control koleksiyonda bulmak için.

Döndürülenler

true Control, koleksiyonun bir üyesiyse; değilse, false.

Örnekler

Aşağıdaki kod örneği, koleksiyonun bir üyesiyse türetilen sınıfın Control öğesinden Control.ControlCollection bir Panel öğesini kaldırır. Örnek, üzerinde bir Panel, ve en az bir ButtonRadioButtonFormdenetim oluşturmanızı gerektirir. Denetimler RadioButton denetimine Panel , denetim de Panel öğesine Formeklenir. Düğmeye tıklandığında, adlı removeButton radyo düğmesi öğesinden Control.ControlCollectionkaldırılır.

   // Remove the RadioButton control if it exists.
private:
   void removeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      if ( panel1->Controls->Contains( removeButton ) )
      {
         panel1->Controls->Remove( removeButton );
      }
   }
// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
{
   if(panel1.Controls.Contains(removeButton))
   {
      panel1.Controls.Remove(removeButton);
   }
}
' Remove the RadioButton control if it exists.
Private Sub RemoveButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles RemoveButton.Click
    If Panel1.Controls.Contains(RemoveButton) Then
        Panel1.Controls.Remove(RemoveButton)
    End If
End Sub

Açıklamalar

Bu yöntem, üzerinde işlem gerçekleştirmeye çalışmadan önce a'nın Control koleksiyonun bir üyesi olup olmadığını belirlemenizi Controlsağlar. bu yöntemi kullanarak bir Control öğesinin eklendiğini veya hala koleksiyonun bir üyesi olduğunu onaylayabilirsiniz.

Şunlara uygulanır

Ayrıca bkz.