Control.ControlCollection.Contains(Control) 메서드

정의

지정된 컨트롤이 컬렉션의 멤버인지 여부를 확인합니다.

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

매개 변수

control
Control

컬렉션에서 찾을 Control입니다.

반환

Boolean

Control이 컬렉션의 멤버이면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 컬렉션의 멤버인 경우 파생 클래스 Panel 에서 Control.ControlCollection 제거 Control 합니다. 이 예제에서는 에 대해 하나 이상의 컨트롤, a Button및 하나 이상의 RadioButton 컨트롤을 Form만들어야 Panel합니다. 컨트롤이 RadioButton 컨트롤에 Panel 추가되고 컨트롤이 Panel 추가됩니다 Form. 단추를 클릭하면 이름이 지정된 removeButton 라디오 단추가 제거 Control.ControlCollection됩니다.

   // 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

설명

이 메서드를 사용하면 에 대한 Control작업을 수행하기 전에 컬렉션의 멤버인지 여부를 Control 확인할 수 있습니다. 이 메서드를 사용하여 컬렉션에 Control 추가되었거나 여전히 컬렉션의 멤버인지 확인할 수 있습니다.

적용 대상

추가 정보