Form.IsMdiContainer 属性

定义

获取或设置一个值,该值指示窗体是否为多文档界面 (MDI) 子窗体的容器。

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;否则,为 false。 默认值为 false

示例

下面的示例演示如何使用 IsMdiContainer 属性以及更改 BackColor MDI 窗体的 属性。 若要运行此示例,请将以下代码粘贴到新窗体中。


// 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 父窗体。 当此属性设置为 true时,窗体将显示具有凸起边框的凹陷工作区。 分配给父窗体的所有 MDI 子窗体都显示在其工作区中。

关闭 MDI 父窗体时, Closing 所有 MDI 子窗体的事件都会在 MDI 父窗体的事件 Closing 引发之前引发。 此外, Closed 所有 MDI 子窗体的事件都是在 MDI 父窗体的 事件引发之前 Closed 引发的。

注意

如果 MDI 子窗体上有两 MenuStrip 个控件,则父窗体的 设置为 IsMdiContainertrue 仅合并其中一个 MenuStrip 控件的内容。 用于 Merge 合并 MDI 父窗体上其他子 MenuStrip 控件的内容。

适用于

另请参阅