Form.IsMdiContainer 属性

定义

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

C#
public bool IsMdiContainer { get; set; }

属性值

如果该窗体是 MDI 子窗体的容器,则为 true;否则,为 false。 默认值为 false

示例

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

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

注解

此属性将窗体的显示和行为更改为 MDI 父窗体。 当此属性设置为 true时,窗体将显示具有凸起边框的凹陷工作区。 分配给父窗体的所有 MDI 子窗体都显示在其工作区中。

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

备注

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

适用于

产品 版本
.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, 10

另请参阅