다음을 통해 공유


Control.Controls 속성

컨트롤에 들어 있는 컨트롤의 컬렉션을 가져옵니다.

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

구문

‘선언
Public ReadOnly Property Controls As ControlCollection
‘사용 방법
Dim instance As Control
Dim value As ControlCollection

value = instance.Controls
public ControlCollection Controls { get; }
public:
property ControlCollection^ Controls {
    ControlCollection^ get ();
}
/** @property */
public ControlCollection get_Controls ()
public function get Controls () : ControlCollection

속성 값

컨트롤에 들어 있는 컨트롤의 컬렉션을 나타내는 Control.ControlCollection입니다.

설명

Control은 컨트롤의 컬렉션에 대한 부모로 동작할 수 있습니다. 예를 들어, 하나의 Form에 여러 개의 컨트롤을 추가하는 경우 각 컨트롤은 Control 클래스에서 파생된 폼의 Controls 속성에 할당된 Control.ControlCollection의 멤버입니다.

Control.ControlCollection 클래스에서 사용할 수 있는 메서드를 통해 Controls 속성에 할당된 Control.ControlCollection의 컨트롤을 조작할 수 있습니다.

하나의 부모 컨트롤에 여러 개의 컨트롤을 추가할 경우 추가할 컨트롤을 초기화하기 전에 SuspendLayout 메서드를 호출하는 것이 좋습니다. 부모 컨트롤에 컨트롤을 추가한 후 ResumeLayout 메서드를 호출합니다. 이렇게 하면 컨트롤이 많은 응용 프로그램의 성능이 향상됩니다.

예제

다음 코드 예제에서는 파생 클래스 PanelControl.ControlCollection에서 컬렉션의 멤버인 Control을 제거합니다. 이 예제를 실행하려면 Form에서 Panel, 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 클래스
Control 멤버
System.Windows.Forms 네임스페이스
Control.ControlCollection
CreateControlsInstance
SuspendLayout
ResumeLayout