Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
Form Class
Form Properties
 ActiveMdiChild Property
Collapse All/Expand All Collapse All
.NET Framework Class Library
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)
Visual Basic
<BrowsableAttribute(False)> _
Public ReadOnly Property ActiveMdiChild As Form
C#
[BrowsableAttribute(false)]
public Form ActiveMdiChild { get; }
Visual C++
[BrowsableAttribute(false)]
public:
property Form^ ActiveMdiChild {
    Form^ get ();
}
F#
[<BrowsableAttribute(false)>]
member ActiveMdiChild : Form

Property Value

Type: System.Windows.Forms..::.Form
Returns a Form that represents the currently active MDI child window, or nullNothingnullptra 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.

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 = "";
       }
    }
 }
    
Visual 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[ i ]) )
         {

            // Clear the contents of the control since it is a TextBox.
            tempChild->Controls[ i ]->Text = "";
         }

      }
   }

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
MDI      Sandh   |   Edit   |   Show History
MDIACTIVE = CHILD.MDIPARENT();
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker