Form.MdiChildren Form.MdiChildren Form.MdiChildren Form.MdiChildren Property

定義

対象のフォームが親フォームであるマルチ ドキュメント インターフェイス (MDI) 子フォームの配列を取得します。Gets an array of forms that represent the multiple-document interface (MDI) child forms that are parented to this form.

public:
 property cli::array <System::Windows::Forms::Form ^> ^ MdiChildren { cli::array <System::Windows::Forms::Form ^> ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] MdiChildren { get; }
member this.MdiChildren : System.Windows.Forms.Form[]
Public ReadOnly Property MdiChildren As Form()

プロパティ値

Form[]

Form オブジェクトの配列。各オブジェクトが、対象となるフォームの MDI 子フォームの 1 つを示します。An array of Form objects, each of which identifies one of this form's MDI child forms.

次のコード例は、使用する方法を示します、 MdiChildren MDI 子フォームのリストを反復処理を追加するプロパティをButton各に制御します。The following code example demonstrates how to use the MdiChildren property to iterate through the list of MDI child forms and add a Button control to each.

private:
   void AddButtonsToMyChildren()
   {
      // If there are child forms in the parent form, add Button controls to them.
      for ( int x = 0; x < this->MdiChildren->Length; x++ )
      {
         // Create a temporary Button control to add to the child form.
         Button^ tempButton = gcnew Button;

         // Set the location and text of the Button control.
         tempButton->Location = Point(10,10);
         tempButton->Text = "OK";

         // Create a temporary instance of a child form (Form 2 in this case).
         Form^ tempChild = dynamic_cast<Form^>(this->MdiChildren[ x ]);

         // Add the Button control to the control collection of the form.
         tempChild->Controls->Add( tempButton );
      }
   }
private void AddButtonsToMyChildren()
{
   // If there are child forms in the parent form, add Button controls to them.
   for (int x =0; x < this.MdiChildren.Length;x++)
   {
      // Create a temporary Button control to add to the child form.
      Button tempButton = new Button();
      // Set the location and text of the Button control.
      tempButton.Location = new Point(10,10);
      tempButton.Text = "OK";
      // Create a temporary instance of a child form (Form 2 in this case).
      Form tempChild = (Form)this.MdiChildren[x];
      // Add the Button control to the control collection of the form.
      tempChild.Controls.Add(tempButton);
   }
}
Private Sub AddButtonsToMyChildren()
    ' If there are child forms in the parent form, add Button controls to them.
    Dim x As Integer
    For x = 0 To (Me.MdiChildren.Length) - 1
        ' Create a temporary Button control to add to the child form.
        Dim tempButton As New Button()
        ' Set the location and text of the Button control.
        tempButton.Location = New Point(10, 10)
        tempButton.Text = "OK"
        ' Create a temporary instance of a child form (Form 2 in this case).
        Dim tempChild As Form = CType(Me.MdiChildren(x), Form)
        ' Add the Button control to the control collection of the form.
        tempChild.Controls.Add(tempButton)
    Next x
End Sub 'AddButtonsToMyChildren

注釈

このプロパティを使用して、MDI 親フォームで現在開いているすべての MDI 子フォームへの参照を取得できます。This property allows you to obtain references to all the MDI child forms currently opened in an MDI parent form. MDI 子フォームを作成するには、割り当て、Formを MDI 親フォームになります、MdiParent子フォームのプロパティ。To create an MDI child form, assign the Form that will be the MDI parent form to the MdiParent property of the child form.

このプロパティは、すべての MDI 子フォーム MDI 親フォームを閉じるときに、データベースにデータを保存するなどの操作を実行するか、アプリケーションで実行されるアクションに基づく子フォームのフィールドを更新するループを使用できます。You can use this property to loop through all the MDI child forms to perform operations such as saving data to a database when the MDI parent form closes or to update fields on the child forms based on actions performed in your application.

適用対象

こちらもご覧ください