Form.ActiveForm Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the currently active form for this application.
public:
static property System::Windows::Forms::Form ^ ActiveForm { System::Windows::Forms::Form ^ get(); };
public static System.Windows.Forms.Form ActiveForm { get; }
public static System.Windows.Forms.Form? ActiveForm { get; }
static member ActiveForm : System.Windows.Forms.Form
Public Shared ReadOnly Property ActiveForm As Form
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.
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.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 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
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
See also
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應