Control.ControlCollection.AddRange(Control[]) Metoda

Definice

Přidá do kolekce pole řídicích objektů.

public:
 virtual void AddRange(cli::array <System::Windows::Forms::Control ^> ^ controls);
public:
 virtual void AddRange(... cli::array <System::Windows::Forms::Control ^> ^ controls);
public virtual void AddRange(System.Windows.Forms.Control[] controls);
public virtual void AddRange(params 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())
Public Overridable Sub AddRange (ParamArray controls As Control())

Parametry

controls
Control[]

Pole Control objektů, které chcete přidat do kolekce.

Příklady

Následující příklad kódu přidá dva Control objekty do Control.ControlCollection odvozené třídy Panel. Příklad vyžaduje, abyste vytvořili Panel ovládací prvek a Button ovládací prvek na objektu Form. Po kliknutí na tlačítko se do panelu RadioButtonpřidají dva Control.ControlCollection ovládací prvky .

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

Poznámky

Objekty Control obsažené v controls poli jsou připojeny na konec kolekce.

Tuto metodu AddRange můžete použít k rychlému přidání skupiny Control objektů do kolekce místo ručního přidávání do Control kolekce pomocí Add metody.

Pokud chcete odebrat dříve přidanou položku Control , použijte metodu Remove, RemoveAtnebo Clear .

Poznámky pro dědice

Při přepsání AddRange(Control[]) v odvozené třídě nezapomeňte volat metodu základní třídy AddRange(Control[]) , aby se zajistilo, že ovládací prvky jsou přidány do kolekce.

Platí pro

Viz také