Control.ControlCollection.AddRange(Control[]) Method

Definition

컨트롤 개체의 배열을 컬렉션에 추가합니다.Adds an array of control objects to the collection.

public:
 virtual void AddRange(cli::array <System::Windows::Forms::Control ^> ^ controls);
public virtual void AddRange (System.Windows.Forms.Control[] controls);
abstract member AddRange : System.Windows.Forms.Control[] -> unit
override this.AddRange : System.Windows.Forms.Control[] -> unit
Public Overridable Sub AddRange (controls As Control())

Parameters

controls
Control[]

컬렉션에 추가할 Control 개체의 배열입니다.An array of Control objects to add to the collection.

Examples

다음 코드 예제에서는 파생 클래스 PanelControl.ControlCollectionControl 개체 두 개를 추가 합니다.The following code example adds two Control objects to the Control.ControlCollection of the derived class Panel. 이 예제를 사용 하려면 Form에서 Panel 컨트롤과 Button 컨트롤을 만들어야 합니다.The example requires that you have created a Panel control and a Button control on a Form. 단추를 클릭 하면 패널의 Control.ControlCollection에 두 개의 RadioButton 컨트롤이 추가 됩니다.When the button is clicked, two RadioButton controls are added to the panel's Control.ControlCollection.

   // Create two RadioButtons to add to the Panel.
private:
   RadioButton^ radioAddButton;
   RadioButton^ radioRemoveButton;

   // Add controls to the Panel using the AddRange method.
   void addRangeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      radioAddButton = gcnew RadioButton;
      radioRemoveButton = gcnew RadioButton;
      
      // Set the Text the RadioButtons will display.
      radioAddButton->Text = "radioAddButton";
      radioRemoveButton->Text = "radioRemoveButton";
      
      // Set the appropriate location of radioRemoveButton.
      radioRemoveButton->Location = System::Drawing::Point( radioAddButton->Location.X, radioAddButton->Location.Y + radioAddButton->Height );
      
      //Add the controls to the Panel.
      array<Control^>^controlArray = {radioAddButton,radioRemoveButton};
      panel1->Controls->AddRange( controlArray );
   }
// Create two RadioButtons to add to the Panel.
private RadioButton radioAddButton = new RadioButton();
private RadioButton radioRemoveButton = new RadioButton();

// Add controls to the Panel using the AddRange method.
private void addRangeButton_Click(object sender, System.EventArgs e)
{
   // Set the Text the RadioButtons will display.
   radioAddButton.Text = "radioAddButton";
   radioRemoveButton.Text = "radioRemoveButton";
            
   // Set the appropriate location of radioRemoveButton.
   radioRemoveButton.Location = new System.Drawing.Point(
     radioAddButton.Location.X, 
     radioAddButton.Location.Y + radioAddButton.Height);
            
   //Add the controls to the Panel.
   panel1.Controls.AddRange(new Control[]{radioAddButton, radioRemoveButton});
}
' Create two RadioButtons to add to the Panel.
Dim RadioAddButton As RadioButton = New RadioButton()
Dim RadioAddRangeButton As RadioButton = New RadioButton()

' Add controls to the Panel using the AddRange method.
Private Sub AddRangeButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles AddRangeButton.Click
    ' Set the Text the RadioButtons will display.
    RadioAddButton.Text = "RadioAddButton"
    RadioAddRangeButton.Text = "RadioAddRangeButton"

    ' Set the appropriate location of RadioAddRangeButton.
    RadioAddRangeButton.Location = New System.Drawing.Point( _
    RadioAddButton.Location.X, _
    RadioAddButton.Location.Y + RadioAddButton.Height)

    ' Add the controls to the Panel.
    Panel1.Controls.AddRange(New Control() {RadioAddButton, RadioAddRangeButton})
End Sub

Remarks

controls 배열에 포함 된 Control 개체는 컬렉션의 끝에 추가 됩니다.The Control objects contained in the controls array are appended to the end of the collection.

Add 메서드를 사용 하 여 컬렉션에 각 Control를 수동으로 추가 하는 대신 AddRange 메서드를 사용 하 여 컬렉션에 Control 개체의 그룹을 빠르게 추가할 수 있습니다.You can use the AddRange method to quickly add a group of Control objects to the collection instead of manually adding each Control to the collection using the Add method.

이전에 추가한 Control를 제거 하려면 Remove, RemoveAt또는 Clear 메서드를 사용 합니다.To remove a Control that you previously added, use the Remove, RemoveAt, or Clear methods.

Notes to Inheritors

파생 클래스에서 AddRange(Control[])를 재정의 하는 경우 컨트롤을 컬렉션에 추가 하도록 기본 클래스의 AddRange(Control[]) 메서드를 호출 해야 합니다.When overriding AddRange(Control[]) in a derived class, be sure to call the base class's AddRange(Control[]) method to ensure that the controls are added to the collection.

Applies to

See also