Control.ControlCollection.AddRange(Control[]) 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将控件对象数组添加到集合中。
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[] -> unitPublic Overridable Sub AddRange (controls As Control())参数
示例
下面的代码示例将两个 Control 对象添加到 Control.ControlCollection 派生类 Panel。 该示例要求你已创建控件Panel和Button控件。Form 单击按钮时,会将两个 RadioButton 控件添加到面板的 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
注解
Control数组中包含的controls对象将追加到集合的末尾。
可以使用该方法AddRange快速将一组Control对象添加到集合,而不是使用Add该方法手动将每个Control对象添加到集合中。
若要删除之前添加的、Control使用Remove或RemoveAtClear方法。
继承者说明
在 AddRange(Control[]) 派生类中重写时,请务必调用基类 AddRange(Control[]) 的方法,以确保将控件添加到集合中。