Export (0) Print
Expand All

Form.ActiveMdiChild Property

Gets the currently active multiple document interface (MDI) child window.

[Visual Basic]
Public ReadOnly Property ActiveMdiChild As Form
[C#]
public Form ActiveMdiChild {get;}
[C++]
public: __property Form* get_ActiveMdiChild();
[JScript]
public function get ActiveMdiChild() : Form;

Property Value

Returns a Form that represents the currently active MDI child window, or a null reference (Nothing in Visual Basic) if there are currently no child windows present.

Remarks

You can use this method to determine whether there are any MDI child forms open in your MDI application. 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.

If the currently active form is not an MDI child form, you can use the ActiveForm property to obtain a reference to it.

Example

[Visual Basic, C#, C++] The following example obtains a reference to the active MDI child form and loops through all TextBox controls on the form, resetting their Text properties. This example assumes that an MDI parent form has been created and that this method call is being made from the MDI parent form.

[Visual Basic] 
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

[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 = "";
       }
    }
 }
    

[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 (dynamic_cast<TextBox*>(tempChild->Controls->Item[i]))
       {
          // Clear the contents of the control since it is a TextBox.
          tempChild->Controls->Item[i]->Text = S"";
       }
    }
 }
    

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Form Class | Form Members | System.Windows.Forms Namespace | ActiveForm

Show:
© 2014 Microsoft