Form.ActiveForm Property

Definition

Gets the currently active form for this application.

public static System.Windows.Forms.Form ActiveForm { get; }
public static System.Windows.Forms.Form? ActiveForm { get; }

Property Value

A Form that represents the currently active form, or null if there is no active form.

Examples

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

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also