Form.MdiChildren プロパティ
対象のフォームが親フォームであるマルチ ドキュメント インターフェイス (MDI) 子フォームの配列を取得します。
Public ReadOnly Property MdiChildren As Form ()
[C#]
public Form[] MdiChildren {get;}
[C++]
public: __property Form* get_MdiChildren();
[JScript]
public function get MdiChildren() : Form[];
プロパティ値
Form オブジェクトの配列。各オブジェクトが、対象となるフォームの MDI 子フォームを示します。
解説
このプロパティを使用すると、MDI 親フォーム上で現在開かれているすべての MDI 子フォームへの参照を取得できます。MDI 子フォームを作成するには、MDI 親フォームになる Form を子フォームの MdiParent プロパティに割り当てます。
このプロパティを使用して、すべての MDI 子フォームをループ処理し、MDI 親フォームが閉じるときにデータベースにデータを保存するなどの操作を実行したり、アプリケーションで実行されるアクションに基づいて子フォームのフィールドを更新したりできます。
使用例
[Visual Basic, C#, C++] MdiChildren プロパティを使用して、MDI 子フォームのリストを反復処理し、すべての子フォームに Button コントロールを追加する例を次に示します。
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
[C#]
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);
}
}
[C++]
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 = Point(10,10);
tempButton->Text = S"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);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
Form クラス | Form メンバ | System.Windows.Forms 名前空間 | IsMdiChild | IsMdiContainer | MdiParent