Form.ActiveMdiChild 属性

定义

获取当前活动的多文档界面 (MDI) 子窗口。

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form ActiveMdiChild { get; }
C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form? ActiveMdiChild { get; }

属性值

Form

返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回 null

属性

示例

以下示例获取对活动 MDI 子窗体的引用,并循环访问窗体上的所有 TextBox 控件,并重置其 Text 属性。 此示例要求已创建 MDI 父窗体,并且此方法调用是从 MDI 父窗体进行的。

C#
public void ClearAllChildFormText()
 {
    // Obtain a reference to the currently active MDI child form.
    Form tempChild = this.ActiveMdiChild;
    
    // Loop through all controls on the child form.
    for (int i = 0; i < tempChild.Controls.Count; i++)
    {
       // Determine if the current control on the child form is a TextBox.
       if (tempChild.Controls[i] is TextBox)
       {
          // Clear the contents of the control since it is a TextBox.
          tempChild.Controls[i].Text = "";
       }
    }
 }

注解

可以使用此方法来确定 MDI 应用程序中是否打开了任何 MDI 子窗体。 还可以使用此方法从 MDI 父窗体或应用程序中显示的另一个窗体对 MDI 子窗口执行操作。

如果当前活动窗体不是 MDI 子窗体,则可以使用该 ActiveForm 属性获取对它的引用。

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅