Form.ActiveForm 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此应用程序的当前活动窗体。
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; }
	member this.ActiveForm : System.Windows.Forms.Form
	Public Shared ReadOnly Property ActiveForm As Form
	属性值
Form,表示当前活动窗体,或者如果没有活动窗体,则为 null。
示例
以下示例获取活动窗体并禁用窗体上的所有控件。 该示例使用 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
	注解
可以使用此方法获取对当前活动窗体的引用,以对窗体或其控件执行操作。
如果应用程序是多文档接口 (MDI) 应用程序,请使用 ActiveMdiChild 该属性获取当前活动的 MDI 子窗体。