다음을 통해 공유


Control.ControlCollection.Clear 메서드

컬렉션에서 컨트롤을 모두 제거합니다.

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

구문

‘선언
Public Overridable Sub Clear
‘사용 방법
Dim instance As ControlCollection

instance.Clear
public virtual void Clear ()
public:
virtual void Clear ()
public void Clear ()
public function Clear ()

설명

Clear 메서드를 사용하면 부모 컨트롤에서 컨트롤의 전체 컬렉션을 제거할 수 있습니다.

컬렉션에서 개별 컨트롤을 제거하려면 Remove 또는 RemoveAt 메서드를 사용합니다.

중요

Clear 메서드를 호출해도 메모리에 있는 컨트롤 핸들은 제거되지 않습니다. 메모리 누수를 방지하려면 Dispose 메서드를 명시적으로 호출해야 합니다.

컬렉션에 새 Control 개체를 추가하려면 Add 또는 AddRange 메서드를 사용합니다.

상속자 참고 사항 파생 클래스에서 Clear를 재정의하는 경우에는 모든 컨트롤이 컬렉션에서 제거되도록 기본 클래스의 Clear 메서드를 호출해야 합니다.

예제

다음 코드 예제에서는 파생 클래스 PanelControl.ControlCollection에 있는 Control 개체를 모두 제거합니다. 이 예제를 실행하려면 먼저 FormPanel, Button 및 적어도 한 개의 다른 컨트롤을 만들어야 합니다. 다른 컨트롤은 Panel 컨트롤에 추가되고, PanelForm에 추가됩니다. 단추를 클릭하면 패널에 포함되어 있는 모든 컨트롤이 Control.ControlCollection에서 제거됩니다.

' Clear all the controls in the Panel.
Private Sub ClearButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles ClearButton.Click
    Panel1.Controls.Clear()
End Sub
// Clear all the controls in the Panel.
private void clearButton_Click(object sender, System.EventArgs e)
{
   panel1.Controls.Clear();
}
   // Clear all the controls in the Panel.
private:
   void clearButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      panel1->Controls->Clear();
   }
// Clear all the controls in the Panel.
private void clearButton_Click(Object sender, System.EventArgs e)
{
    panel1.get_Controls().Clear();
} //clearButton_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 네임스페이스