Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
Form Class
Form Properties
 ActiveForm Property
Collapse All/Expand All Collapse All
.NET Framework Class Library
Form..::.ActiveForm Property

Gets the currently active form for this application.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public Shared ReadOnly Property ActiveForm As Form
C#
public static Form ActiveForm { get; }
Visual C++
public:
static property Form^ ActiveForm {
    Form^ get ();
}
F#
static member ActiveForm : Form

Property Value

Type: System.Windows.Forms..::.Form
A Form that represents the currently active form, or nullNothingnullptra null reference (Nothing in Visual Basic) if there is no active form.

You can use this method to obtain a reference to the currently active form to perform actions on the form or its controls.

If your application is a multiple-document interface (MDI) application, use the ActiveMdiChild property to obtain the currently active MDI child form.

The following code example gets the active form and disables all the controls on the form. The example uses the Controls collection of the form to iterate through each control on the form and disable the controls.

Visual Basic
Public Sub DisableActiveFormControls()
    ' Create an instance of a form and assign it the currently active form.
    Dim currentForm As Form = Form.ActiveForm

    ' Loop through all the controls on the active form.
    Dim i As Integer
    For i = 0 To currentForm.Controls.Count - 1
        ' Disable each control in the active form's control collection.
        currentForm.Controls(i).Enabled = False
    Next i
End Sub 'DisableActiveFormControls
C#
public void DisableActiveFormControls()
 {
    // Create an instance of a form and assign it the currently active form.
    Form currentForm = Form.ActiveForm;

    // Loop through all the controls on the active form.
    for (int i = 0; i < currentForm.Controls.Count; i++)
    {
       // Disable each control in the active form's control collection.
       currentForm.Controls[i].Enabled = false;
    }
 }
    
Visual C++
   void DisableActiveFormControls()
   {

      // Create an instance of a form and assign it the currently active form.
      Form^ currentForm = Form::ActiveForm;

      // Loop through all the controls on the active form.
      for ( int i = 0; i < currentForm->Controls->Count; i++ )
      {

         // Disable each control in the active form's control collection.
         currentForm->Controls[ i ]->Enabled = false;

      }
   }

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

    for requesting a form. Associated enumeration: UIPermissionWindow..::.AllWindows.

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
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker