Control.ControlCollection.AddRange(Control[]) Control.ControlCollection.AddRange(Control[]) Control.ControlCollection.AddRange(Control[]) Control.ControlCollection.AddRange(Control[]) Method

定義

コレクションにコントロール オブジェクトの配列を追加します。Adds an array of control objects to the collection.

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())

パラメーター

controls
Control[]

コレクションに追加する Control オブジェクトの配列。An array of Control objects to add to the collection.

次のコード例ではControl 、派生クラスControl.ControlCollection Panelのに2つのオブジェクトを追加します。The following code example adds two Control objects to the Control.ControlCollection of the derived class Panel. この例では、にPanel FormコントロールButtonとコントロールを作成しておく必要があります。The example requires that you have created a Panel control and a Button control on a Form. ボタンがクリックされると、 RadioButton 2 つのコントロールがパネルのControl.ControlCollectionに追加されます。When the button is clicked, two RadioButton controls are added to the panel's 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れます。The Control objects contained in the controls array are appended to the end of the collection.

メソッドを使用AddRangeすると、 Addメソッドを使用してControlコレクションにオブジェクトを手動でControl追加するのではなく、オブジェクトのグループをコレクションにすばやく追加できます。You can use the AddRange method to quickly add a group of Control objects to the collection instead of manually adding each Control to the collection using the Add method.

以前に追加Controlしたを削除するにはRemove、メソッド、 Clearメソッド、またはメソッドを使用RemoveAtします。To remove a Control that you previously added, use the Remove, RemoveAt, or Clear methods.

注意 (継承者)

派生クラスAddRange(Control[])でをオーバーライドする場合は、必ず、基本クラスのAddRange(Control[])メソッドを呼び出して、コントロールが確実にコレクションに追加されるようにしてください。When overriding AddRange(Control[]) in a derived class, be sure to call the base class's AddRange(Control[]) method to ensure that the controls are added to the collection.

適用対象

こちらもご覧ください