Form.ActiveForm 属性

定义

获取此应用程序的当前活动窗体。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; }
member this.ActiveForm : System.Windows.Forms.Form
Public Shared ReadOnly Property ActiveForm As Form

属性值

Form,表示当前活动窗体,或者如果没有活动窗体,则为 nullA Form that represents the currently active form, or null if there is no active form.

示例

下面的示例获取活动窗体,并禁用窗体上的所有控件。The following example gets the active form and disables all the controls on the form. 该示例使用窗体的 Controls 集合来循环访问窗体上的每个控件并禁用控件。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

注解

您可以使用此方法获取对当前活动窗体的引用,以便在窗体或其控件上执行操作。You can use this method to obtain a reference to the currently active form to perform actions on the form or its controls.

如果你的应用程序是多文档界面(MDI)应用程序,请使用 ActiveMdiChild 属性获取当前活动的 MDI 子窗体。If your application is a multiple-document interface (MDI) application, use the ActiveMdiChild property to obtain the currently active MDI child form.

安全性

UIPermission
用于请求窗体。for requesting a form. 关联枚举:AllWindowsAssociated enumeration: AllWindows.

适用于

另请参阅