Control.ControlCollection.AddRange(Control[]) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee voegt u een matrix met besturingsobjecten toe aan de verzameling.
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
Voorbeelden
In het volgende codevoorbeeld worden twee Control objecten toegevoegd aan de Control.ControlCollection afgeleide klasse Panel. In het voorbeeld moet u een Panel besturingselement en een Button besturingselement op een Formhebben gemaakt. Wanneer op de knop wordt geklikt, worden er twee RadioButton besturingselementen toegevoegd aan het deelvenster 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
Opmerkingen
De Control objecten in de controls matrix worden toegevoegd aan het einde van de verzameling.
U kunt de AddRange methode gebruiken om snel een groep Control objecten aan de verzameling toe te voegen in plaats van ze Control handmatig aan de verzameling toe te voegen met behulp van de Add methode.
Als u een Control die u eerder hebt toegevoegd, wilt verwijderen, gebruikt u de Removeof RemoveAtClear methoden.
Notities voor overnemers
Wanneer u AddRange(Control[]) overschrijft in een afgeleide klasse, moet u de methode van AddRange(Control[]) de basisklasse aanroepen om ervoor te zorgen dat de besturingselementen aan de verzameling worden toegevoegd.