Gets the currently active form for this application.
[Visual Basic] Public Shared ReadOnly Property ActiveForm As Form [C#] public static Form ActiveForm {get;} [C++] public: __property static Form* get_ActiveForm(); [JScript] public static function get ActiveForm() : Form;
A Form that represents the currently active form, or a a null reference (in Visual Basic Nothing) 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 example gets the active form and makes all of the controls on the form disabled. The example uses the Controls collection of the form to iterate through each control on the form and disable the contriols.
[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; } }
Form Class | Form Members | System.WinForms Namespace | ActiveMDIChild