Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Fügt der Auflistung ein Array von Steuerelementobjekten hinzu.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Overridable Sub AddRange ( _
controls As Control() _
)
'Usage
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[]
)
Parameter
- controls
Ein Array von Control-Objekten, die der Auflistung hinzugefügt werden sollen.
Hinweise
Die im controls-Array enthaltenen Control-Objekte werden am Ende der Auflistung angefügt.
Mit der AddRange-Methode können Sie der Auflistung eine Gruppe von Control-Objekten schnell hinzufügen, statt jedes Controlmit der Add-Methode manuell hinzuzufügen.
Verwenden Sie die Remove-Methode, die RemoveAt-Methode oder die Clear-Methode, um ein zuvor hinzugefügtes Control zu entfernen.
Hinweise für Erben Wenn Sie AddRange in einer abgeleiteten Klasse überschreiben, müssen Sie die AddRange-Methode der Basisklasse aufrufen, um sicherzustellen, dass die Steuerelemente der Auflistung hinzugefügt werden.
Beispiel
Im folgenden Codebeispiel werden der Control.ControlCollection des Panel der abgeleiteten Klasse zwei Control-Objekte hinzugefügt. Im Beispiel wird davon ausgegangen, dass ein Panel-Steuerelement und ein Button-Steuerelement in einem Form erstellt wurden. Beim Klicken auf die Schaltfläche werden der Control.ControlCollection des Bereichs zwei RadioButton-Steuerelemente hinzugefügt.
' 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
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
Control.ControlCollection-Klasse
Control.ControlCollection-Member
System.Windows.Forms-Namespace
Add