共用方式為


Form.ActiveMdiChild 屬性

定義

取得目前現用的多重文件介面 (MDI) 子視窗。

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

屬性值

Form

傳回 Form,代表目前現用 MDI 子視窗;如果目前沒有子視窗,則為 null

屬性

範例

下列範例會取得使用中 MDI 子表單的參考,並迴圈查看表單上的所有 TextBox 控制項,並重設其 Text 屬性。 這個範例會要求已建立 MDI 父表單,而且這個方法呼叫是從 MDI 父表單進行。

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

備註

您可以使用這個方法來判斷 MDI 應用程式中是否開啟任何 MDI 子表單。 您也可以使用這個方法,從 MDI 父表單或應用程式中顯示的另一個表單,對 MDI 子視窗執行作業。

如果目前使用中的表單不是 MDI 子表單,您可以使用 ActiveForm 屬性來取得它的參考。

適用於

另請參閱