Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Form.ControlCollection.Add(Control) Method

정의

폼에 컨트롤을 추가합니다.Adds a control to the form.

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 Control Control

폼에 추가할 Control입니다.The Control to add to the form.

예외

MDI(다중 문서 인터페이스) 부모 폼에 컨트롤을 추가할 수 없는 경우A multiple document interface (MDI) parent form cannot have controls added to it.

예제

다음 코드 예제에서는 추가 된 TextBoxLabel 컨트롤을 폼의 컨트롤 컬렉션입니다.The following code example adds a TextBox and Label control to the control collection of a form. 예제는 폼이 되어 라는 Form1합니다.The example requires that a form has been created and named 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

설명

폼에 컨트롤을 추가 하려면이 메서드를 사용할 수 있습니다.You can use this method to add controls to the form. 이미 만들어진된 컨트롤 그룹을 폼에 추가 하려는 경우 사용 합니다 Control.ControlCollection.AddRange 메서드를 Control.ControlCollection 클래스.If you want to add a group of already created controls to the form, use the Control.ControlCollection.AddRange method of the Control.ControlCollection class.

적용 대상

추가 정보