Form.ControlCollection.Add(Control) 메서드

정의

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

public:
 override void Add(System::Windows::Forms::Control ^ value);
public override void Add(System.Windows.Forms.Control value);
public override void Add(System.Windows.Forms.Control? value);
override this.Add : System.Windows.Forms.Control -> unit
Public Overrides Sub Add (value As Control)

매개 변수

value
Control

Control 폼에 추가할 형식입니다.

예외

MDI(다중 문서 인터페이스) 부모 폼에는 컨트롤이 추가될 수 없습니다.

예제

다음 코드 예제에서는 폼의 TextBox 컨트롤 컬렉션에 a 및 Label 컨트롤을 추가합니다. 이 예제에서는 폼을 만들고 이름을 지정 Form1해야 합니다.

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 );
   }
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 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

설명

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

적용 대상

추가 정보