Export (0) Print
Expand All

Form.ActiveForm Property

Gets the currently active form for this application.

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

public static Form ActiveForm { get; }
/** @property */
public static Form get_ActiveForm ()

public static function get ActiveForm () : Form

Not applicable.

Property Value

A Form that represents the currently active form, or a 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.

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;
    }
 }
    

public void DisableActiveFormControls()
{
    // Create an instance of a form and assign it the currently 
    // active form.
    Form currentForm = Form.get_ActiveForm();

    // Loop through all the controls on the active form.
    for (int i = 0; i < currentForm.get_Controls().get_Count(); i++) {
        // Disable each control in the active form's control collection.
        currentForm.get_Controls().get_Item(i).set_Enabled(false);
    }
} //DisableActiveFormControls

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft