Control.ControlCollection.AddRange(Control[]) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Adiciona um conjunto de objetos de controlo à coleção.
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())
Parâmetros
Exemplos
O seguinte exemplo de código adiciona dois Control objetos ao Control.ControlCollection da classe Panelderivada . O exemplo exige que tenha criado um Panel controlo e um Button controlo sobre um Form. Quando o botão é pressionado, dois RadioButton controlos são adicionados ao Control.ControlCollectionpainel .
// 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
Observações
Os Control objetos contidos no controls array são anexados ao final da coleção.
Pode usar o AddRange método para adicionar rapidamente um grupo de Control objetos à coleção em vez de adicionar manualmente cada um Control à coleção usando o Add método.
Para remover um Control que adicionou anteriormente, use os Removemétodos , RemoveAt, ou Clear .
Notas para Herdeiros
Ao substituir AddRange(Control[]) uma classe derivada, certifique-se de chamar o método da AddRange(Control[]) classe base para garantir que os controlos são adicionados à coleção.