Form.ActiveMdiChild 属性

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

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

语法

声明
Public ReadOnly Property ActiveMdiChild As Form
用法
Dim instance As Form
Dim value As Form

value = instance.ActiveMdiChild
public Form ActiveMdiChild { get; }
public:
property Form^ ActiveMdiChild {
    Form^ get ();
}
/** @property */
public Form get_ActiveMdiChild ()
public function get ActiveMdiChild () : Form

属性值

返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回 空引用(在 Visual Basic 中为 Nothing)。

备注

可使用此方法确定 MDI 应用程序中是否有任何打开的 MDI 子窗体。也可使用此方法从 MDI 子窗口的 MDI 父窗体或者从应用程序中显示的其他窗体对该 MDI 子窗口执行操作。

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

示例

下面的代码示例获取对活动 MDI 子窗体的引用,并依次通过该窗体上的所有 TextBox 控件,重置这些控件的 Text 属性。此示例要求已创建 MDI 父窗体,而且从 MDI 父窗体执行此方法调用。

Public Sub ClearAllChildFormText()
    ' Obtain a reference to the currently active MDI child form.
    Dim tempChild As Form = Me.ActiveMdiChild
    
    ' Loop through all controls on the child form.
    Dim i As Integer
    For i = 0 To tempChild.Controls.Count - 1
        ' Determine if the current control on the child form is a TextBox.
        If TypeOf tempChild.Controls(i) Is TextBox Then
            ' Clear the contents of the control since it is a TextBox.
            tempChild.Controls(i).Text = ""
        End If
    Next i
End Sub 'ClearAllChildFormText
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 = "";
       }
    }
 }
    
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 ( dynamic_cast<TextBox^>(tempChild->Controls[ i ]) )
         {
            
            // Clear the contents of the control since it is a TextBox.
            tempChild->Controls[ i ]->Text = "";
         }

      }
   }
public void ClearAllChildFormText()
{
    // Obtain a reference to the currently active MDI child form.
    Form tempChild = this.get_ActiveMdiChild();

    // Loop through all controls on the child form.
    for (int i = 0; i < tempChild.get_Controls().get_Count(); i++) {
        // Determine if the current control on the child form is a 
        // TextBox.
        if (tempChild.get_Controls().get_Item(i) instanceof TextBox) {
            // Clear the contents of the control since it is a TextBox.
            tempChild.get_Controls().get_Item(i).set_Text("");
        }
    }
} //ClearAllChildFormText

平台

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.ActiveForm 属性