다음을 통해 공유


Control.ControlCollection.Contains 메서드

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Function Contains ( _
    control As Control _
) As Boolean
‘사용 방법
Dim instance As ControlCollection
Dim control As Control
Dim returnValue As Boolean

returnValue = instance.Contains(control)
public bool Contains (
    Control control
)
public:
bool Contains (
    Control^ control
)
public boolean Contains (
    Control control
)
public function Contains (
    control : Control
) : boolean

매개 변수

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

반환 값

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

설명

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

예제

다음 코드 예제에서는 파생 클래스 PanelControl.ControlCollection에서 컬렉션의 멤버인 Control을 제거합니다. 이 예제를 실행하려면 FormPanel, Button 및 적어도 한 개의 RadioButton 컨트롤이 만들어져 있어야 합니다. RadioButton 컨트롤은 Panel 컨트롤에 추가되고, Panel 컨트롤은 Form에 추가됩니다. 단추를 클릭하면 radioButton2 라디오 단추가 Control.ControlCollection에서 제거됩니다.

' 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(RadioAddRangeButton) Then
        Panel1.Controls.Remove(RadioAddRangeButton)
    End If
End Sub
// 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 void removeButton_Click(Object sender, System.EventArgs e)
{
    if (panel1.get_Controls().Contains(removeButton)) {
        panel1.get_Controls().Remove(removeButton);
    }
} //removeButton_Click

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Control.ControlCollection 클래스
Control.ControlCollection 멤버
System.Windows.Forms 네임스페이스
Control 클래스