Export (0) Print
Expand All

Form.ActiveMdiChild Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Form ActiveMdiChild { get; }
/** @property */
public Form get_ActiveMdiChild ()

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.

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.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft