Form.IsMdiContainer 属性

定义

获取或设置一个值,该值指示窗体是否为多文档界面 (MDI) 子窗体的容器。Gets or sets a value indicating whether the form is a container for multiple-document interface (MDI) child forms.

public:
 property bool IsMdiContainer { bool get(); void set(bool value); };
public bool IsMdiContainer { get; set; }
member this.IsMdiContainer : bool with get, set
Public Property IsMdiContainer As Boolean

属性值

如果该窗体是 MDI 子窗体的容器,则为 true;否则,为 falsetrue if the form is a container for MDI child forms; otherwise, false. 默认值为 falseThe default is false.

示例

下面的示例演示如何使用 IsMdiContainer 属性以及更改 MDI 窗体的 BackColor 属性。The following 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.


// 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;
        }
    }

}

' 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

注解

此属性将窗体的显示和行为更改为 MDI 父窗体。This property changes the display and behavior of the form to an MDI parent form. 如果将此属性设置为 true,则窗体将显示具有凸起边框的凹陷工作区。When this property is set to true, the form displays a sunken client area with a raised border. 分配给父窗体的所有 MDI 子窗体都显示在其工作区中。All MDI child forms assigned to the parent form are displayed within its client area.

当关闭 MDI 父窗体时,在引发 MDI 父窗体的 Closing 事件之前,将引发所有 MDI 子窗体的 Closing 事件。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. 此外,在引发 MDI 父窗体的 Closed 事件之前,将引发所有 MDI 子窗体的 Closed 事件。In addition, the Closed events of all MDI child forms are raised before the Closed event of the MDI parent form is raised.

备注

如果 MDI 子窗体上有两个 MenuStrip 控件,则将 IsMdiContainer 设置为父窗体 true 只会合并某个 MenuStrip 控件的内容。If there are two MenuStrip controls on an MDI child form, setting IsMdiContainer to true for the parent form merges the contents of only one of the MenuStrip controls. 使用 Merge 在 MDI 父窗体上合并其他子 MenuStrip 控件的内容。Use Merge to merge the contents of additional child MenuStrip controls on the MDI parent form.

适用于

另请参阅