共用方式為


Form.ActiveForm 屬性

定義

取得這個應用程式目前的現用表單。

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

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 子表單。

適用於

另請參閱