다음을 통해 공유


Control.ControlCollection.AddRange 메서드

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

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

구문

‘선언
Public Overridable Sub AddRange ( _
    controls As Control() _
)
‘사용 방법
Dim instance As ControlCollection
Dim controls As Control()

instance.AddRange(controls)
public virtual void AddRange (
    Control[] controls
)
public:
virtual void AddRange (
    array<Control^>^ controls
)
public void AddRange (
    Control[] controls
)
public function AddRange (
    controls : Control[]
)

매개 변수

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

설명

controls 배열에 들어 있는 Control 개체는 컬렉션의 끝에 추가됩니다.

Add 메서드를 사용하여 컬렉션에 각 Control을 직접 추가하는 대신 AddRange 메서드를 사용하여 Control 개체의 그룹을 컬렉션에 신속하게 추가할 수 있습니다.

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

상속자 참고 사항 파생 클래스에서 AddRange를 재정의하는 경우에는 컨트롤이 컬렉션에 추가되도록 기본 클래스의 AddRange 메서드를 호출해야 합니다.

예제

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

' 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
// 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.
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.set_Text("radioAddButton");
    radioRemoveButton.set_Text("radioRemoveButton");

    // Set the appropriate location of radioRemoveButton.
    radioRemoveButton.set_Location(new System.Drawing.Point(radioAddButton.
        get_Location().get_X(), radioAddButton.get_Location().get_Y() 
        + radioAddButton.get_Height()));

    //Add the controls to the Panel.
    panel1.get_Controls().AddRange(new Control[] { radioAddButton, 
        radioRemoveButton });
} //addRangeButton_Click

플랫폼

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

참고 항목

참조

Control.ControlCollection 클래스
Control.ControlCollection 멤버
System.Windows.Forms 네임스페이스
Add