Control.ControlCollection.AddRange(Control[]) 메서드

정의

컨트롤 개체의 배열을 컬렉션에 추가합니다.

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())

매개 변수

controls
Control[]

컬렉션에 추가할 Control 개체의 배열입니다.

예제

다음 코드 예제에서는 파생 클래스PanelControl.ControlCollectionControl 개체를 추가합니다. 이 예제에서는 컨트롤과 컨트롤을 Panel Button 만들어야 합니다 Form. 단추를 클릭하면 패널Control.ControlCollection에 두 개의 RadioButton 컨트롤이 추가됩니다.

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

설명

Control 배열에 controls 포함된 개체는 컬렉션의 끝에 추가됩니다.

메서드를 사용하여 컬렉션에 AddRange 각각 Control 을 수동으로 추가하는 대신 개체 그룹을 Control 컬렉션 Add 에 빠르게 추가할 수 있습니다.

이전에 추가한 Control 항목을 제거하려면 , RemoveAt또는 Clear 메서드를 Remove사용합니다.

상속자 참고

파생 클래스에서 재정의하는 AddRange(Control[]) 경우 기본 클래스의 AddRange(Control[]) 메서드를 호출하여 컨트롤이 컬렉션에 추가되도록 해야 합니다.

적용 대상

추가 정보