다음을 통해 공유


Form.ControlCollection.Add 메서드

폼에 컨트롤을 추가합니다.

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

구문

‘선언
Public Overrides Sub Add ( _
    value As Control _
)
‘사용 방법
Dim instance As ControlCollection
Dim value As Control

instance.Add(value)
public override void Add (
    Control value
)
public:
virtual void Add (
    Control^ value
) override
public void Add (
    Control value
)
public override function Add (
    value : Control
)

매개 변수

  • value
    폼에 추가할 Control입니다.

예외

예외 형식 조건

Exception

MDI(다중 문서 인터페이스) 부모 폼에 컨트롤을 추가할 수 없는 경우

설명

이 메서드를 사용하여 폼에 컨트롤을 추가할 수 있습니다. 이미 만들어진 컨트롤 그룹을 폼에 추가하려면 Control.ControlCollection 클래스의 Control.ControlCollection.AddRange 메서드를 사용합니다.

예제

다음 코드 예제에서는 폼의 컨트롤 컬렉션에 TextBoxLabel 컨트롤을 추가합니다. 이 예제를 실행하려면 먼저 Form1이라는 폼을 만들어야 합니다.

Public Sub AddMyControls()
    Dim textBox1 As New TextBox()
    Dim label1 As New Label()
    
    ' Initialize the controls and their bounds.
    label1.Text = "First Name"
    label1.Location = New Point(48, 48)
    label1.Size = New Size(104, 16)
    textBox1.Text = ""
    textBox1.Location = New Point(48, 64)
    textBox1.Size = New Size(104, 16)
    
    ' Add the TextBox control to the form's control collection.
    Controls.Add(textBox1)
    ' Add the Label control to the form's control collection.
    Controls.Add(label1)
End Sub 'AddMyControls
public void AddMyControls()
 {
    TextBox textBox1 = new TextBox();
    Label label1 = new Label();
    
    // Initialize the controls and their bounds.
    label1.Text = "First Name";
    label1.Location = new Point(48,48);
    label1.Size = new Size (104, 16);
    textBox1.Text = "";
    textBox1.Location = new Point(48, 64);
    textBox1.Size = new Size(104,16);
 
    // Add the TextBox control to the form's control collection.
    Controls.Add(textBox1);
    // Add the Label control to the form's control collection.
    Controls.Add(label1);
 }
 
public:
   void AddMyControls()
   {
      TextBox^ textBox1 = gcnew TextBox;
      Label^ label1 = gcnew Label;
      
      // Initialize the controls and their bounds.
      label1->Text = "First Name";
      label1->Location = Point( 48, 48 );
      label1->Size = System::Drawing::Size( 104, 16 );
      textBox1->Text = "";
      textBox1->Location = Point(48,64);
      textBox1->Size = System::Drawing::Size( 104, 16 );
      
      // Add the TextBox control to the form's control collection.
      Controls->Add( textBox1 );
      // Add the Label control to the form's control collection.
      Controls->Add( label1 );
   }

플랫폼

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에서 지원

참고 항목

참조

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