Form.IsMdiContainer 属性

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

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property IsMdiContainer As Boolean
用法
Dim instance As Form
Dim value As Boolean

value = instance.IsMdiContainer

instance.IsMdiContainer = value
public bool IsMdiContainer { get; set; }
public:
property bool IsMdiContainer {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_IsMdiContainer ()

/** @property */
public void set_IsMdiContainer (boolean value)
public function get IsMdiContainer () : boolean

public function set IsMdiContainer (value : boolean)

属性值

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

备注

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

当关闭 MDI 父窗体时,引发 MDI 父窗体的 Closing 事件,随后引发所有 MDI 子窗体的 Closing 事件。另外,在引发 MDI 父窗体的 Closed 事件之前,将引发所有 MDI 子窗体的 Closed 事件。

示例

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

' 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
// 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.
private Form mdiChildForm = new Form();

private void Form1_Load(Object sender, System.EventArgs e)
{
    // Set the IsMdiContainer property to true.
    set_IsMdiContainer(true);

    // Set the child form's MdiParent property to 
    // the current form.
    mdiChildForm.set_MdiParent(this);

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

private void SetBackGroundColorOfMDIForm()
{
    for (int iCtr = 0; iCtr < this.get_Controls().get_Count(); iCtr++) {
        Control ctl = this.get_Controls().get_Item(iCtr);
        if (ctl instanceof MdiClient) {
            // If the control is the correct type,
            // change the color.
            ctl.set_BackColor(System.Drawing.Color.get_PaleGreen());
        }
    }
} //SetBackGroundColorOfMDIForm

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
Form.IsMdiChild 属性
MdiParent
MdiChildren