Form.MdiChildren Property

Definition

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

[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] MdiChildren { get; }

Property Value

Form[]

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

Attributes

Examples

The following 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 = 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);
   }
}

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also