This documentation is archived and is not being maintained.

Form.IsMdiContainer Property

Gets or sets a value indicating whether the form is a container for multiple document interface (MDI) child forms.

[Visual Basic]
Public Property IsMdiContainer As Boolean
[C#]
public bool IsMdiContainer {get; set;}
[C++]
public: __property bool get_IsMdiContainer();
public: __property void set_IsMdiContainer(bool);
[JScript]
public function get IsMdiContainer() : Boolean;
public function set IsMdiContainer(Boolean);

Property Value

true if the form is a container for MDI child forms; otherwise, false. The default is false.

Remarks

This property changes the display and behavior of the form to an MDI parent form. When this property is set to true, the form displays a sunken client area with a raised border. All MDI child forms assigned to the parent form are displayed within its client area.

When an MDI parent form is closed, the Closing events of all MDI child forms are raised before the MDI parent form's Closing event is raised. In addition, the Closed events of all MDI child forms are raised before the Closed event of the MDI parent form is raised.

Example

[Visual Basic, C#] The following code example demonstrates using the IsMdiContainer property as well as changing the BackColor property of an MDI Form. To run this example paste the following code in a new form.

[Visual Basic] 

    ' Create a new form.
    Dim mdiChildForm As New Form

    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        ' Set the IsMdiContainer property to true.
        IsMdiContainer = True

        ' Set the child form's MdiParent property to 
        ' the current form.
        mdiChildForm.MdiParent = Me

        'Call the method that changes the background color.
        SetBackGroundColorOfMDIForm()
    End Sub

    Private Sub SetBackGroundColorOfMDIForm()
        Dim ctl As Control

        ' Loop through controls,  
        ' looking for controls of MdiClient type. 
        For Each ctl In Me.Controls
            If TypeOf (ctl) Is MdiClient Then

                ' If the control is the correct type,
                ' change the color.
                ctl.BackColor = System.Drawing.Color.PaleGreen
            End If
        Next

    End Sub

[C#] 

    // Create a new form.
    Form mdiChildForm = new Form();

    private void Form1_Load(object sender, System.EventArgs e)
    {

        // Set the IsMdiContainer property to true.
        IsMdiContainer = true;

        // Set the child form's MdiParent property to 
        // the current form.
        mdiChildForm.MdiParent = this;

        // Call the method that changes the background color.
        SetBackGroundColorOfMDIForm();
    }

    private void SetBackGroundColorOfMDIForm()
    {
        foreach ( Control ctl in this.Controls )
        {
            if ((ctl) is MdiClient)

                // If the control is the correct type,
                // change the color.
            {
                ctl.BackColor = System.Drawing.Color.PaleGreen;
            }
        }

    }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic 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

See Also

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

Show: