Form.ActiveMdiChild Form.ActiveMdiChild Form.ActiveMdiChild Form.ActiveMdiChild Property

定义

获取当前活动的多文档界面 (MDI) 子窗口。Gets the currently active multiple-document interface (MDI) child window.

public:
 property System::Windows::Forms::Form ^ ActiveMdiChild { System::Windows::Forms::Form ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form ActiveMdiChild { get; }
member this.ActiveMdiChild : System.Windows.Forms.Form
Public ReadOnly Property ActiveMdiChild As Form

属性值

返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回 nullReturns a Form that represents the currently active MDI child window, or null if there are currently no child windows present.

示例

下面的代码示例获取对活动的 MDI 子窗体,并循环访问所有的引用TextBox控件在窗体上的重置其Text属性。The following code example obtains a reference to the active MDI child form and loops through all TextBox controls on the form, resetting their Text properties. 此示例要求已创建的 MDI 父窗体,此方法调用进行了从 MDI 父窗体。This example requires that an MDI parent form has been created and that this method call is being made from the MDI parent form.

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.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 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

注解

此方法可用于确定是否有任何 MDI 子窗体 MDI 应用程序中打开。You can use this method to determine whether there are any MDI child forms open in your MDI application. 此方法还可用于从其 MDI 父窗体或从另一种形式显示在你的应用程序中执行的 MDI 子窗口上的操作。You can also use this method to perform operations on an MDI child window from its MDI parent form or from another form that is displayed in your application.

如果当前活动窗体不是 MDI 子窗体,则可以使用ActiveForm属性来获取对它的引用。If the currently active form is not an MDI child form, you can use the ActiveForm property to obtain a reference to it.

适用于

另请参阅