This documentation is archived and is not being maintained.

Form.MdiParent Property

Gets or sets the current multiple document interface (MDI) parent form of this form.

[Visual Basic]
Public Property MdiParent As Form
[C#]
public Form MdiParent {get; set;}
[C++]
public: __property Form* get_MdiParent();
public: __property void set_MdiParent(Form*);
[JScript]
public function get MdiParent() : Form;
public function set MdiParent(Form);

Property Value

A Form that represents the MDI parent form.

Exceptions

Exception Type Condition
Exception The Form assigned to this property is not marked as an MDI container.

-or-

The Form assigned to this property is both a child and an MDI container form.

-or-

The Form assigned to this property is located on a different thread.

Remarks

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 from an MDI child form to obtain global information that all child forms need or to invoke methods that perform actions to all child forms.

Example

[Visual Basic, C#, C++] The following example demonstrates how to create child forms in an MDI application. The example code creates a form with unique text to identify the child form. The example uses the MdiParent property to specify that a form is a child form. This example assumes that the code in the example is called from a form that has its IsMdiContainer property set to true and that the form has a private class level integer variable named childCount.

[Visual Basic] 
Private Sub CreateMyChildForm()
   ' Create a new form to represent the child form.
   Dim child As New Form()
   ' Increment the private child count.
   childCount += 1
   ' Set the text of the child form using the count of child forms.
   Dim formText As String = "Child " + childCount.ToString()
   child.Text = formText

   ' Make the new form a child form.
   child.MdiParent = Me
   ' Display the child form.
   child.Show()
End Sub

[C#] 
private void CreateMyChildForm ()
{
   // Create a new form to represent the child form.
   Form child = new Form();
   // Increment the private child count.
   childCount++;
   // Set the text of the child form using the count of child forms.
   String formText = "Child " + childCount;
   child.Text = formText;

   // Make the new form a child form.
   child.MdiParent = this;
   // Display the child form.
   child.Show();
}

[C++] 
private:
   void CreateMyChildForm ()
   {
      // Create a new form to represent the child form.
      Form* child = new Form();
      // Increment the private child count.
      childCount++;
      // Set the text of the child form using the count of child forms.
      String* formText = String::Format( S"Child {0}", __box(childCount));
      child->Text = formText;

      // Make the new form a child form.
      child->MdiParent = this;
      // Display the child form.
      child->Show();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Form Class | Form Members | System.Windows.Forms Namespace | IsMdiChild | IsMdiContainer | MdiChildren

Show: