Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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:
property Form^ ActiveForm {
	static Form^ get();
}

Property Value

Type: System.Windows.Forms::Form^

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

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;

   }
}

UIPermission

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

.NET Framework
Available since 1.1
Return to top
Show:
© 2017 Microsoft