Export (0) Print
Expand All

Form.MdiChildren Property

Gets an array of forms that represent the multiple-document interface (MDI) child forms that are parented to this form.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

'Declaration
Public ReadOnly Property MdiChildren As Form()
'Usage
Dim instance As Form
Dim value As Form()

value = instance.MdiChildren

/** @property */
public Form[] get_MdiChildren ()

public function get MdiChildren () : Form[]

Not applicable.

Property Value

An array of Form objects, each of which identifies one of this form's MDI child forms.

This property allows you to obtain references to all the MDI child forms currently opened in an MDI parent form. To create an MDI child form, assign the Form that will be the MDI parent form to the MdiParent property of the child form.

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.

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

private void AddButtonsToMyChildren()
{
    // If there are child forms in the parent form, add 
    // Button controls to them.
    for (int x = 0; x < this.get_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.set_Location(new Point(10, 10));
        tempButton.set_Text("OK");

        // Create a temporary instance of a child form
        //(Form 2 in this case).
        Form tempChild = (Form)(this.get_MdiChildren().get_Item(x));

        // Add the Button control to the control collection of the form.
        tempChild.get_Controls().Add(tempButton);
    }
} //AddButtonsToMyChildren

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft