Freigeben über


Form.ActiveForm Eigenschaft

Definition

Ruft das derzeit aktive Formular für diese Anwendung ab.

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

Eigenschaftswert

A Form that represents the currently active form, or null if there is no active form.

Beispiele

Im folgenden Beispiel wird das aktive Formular aufgerufen und alle Steuerelemente im Formular deaktiviert. Im Beispiel wird die Controls Auflistung des Formulars verwendet, um jedes Steuerelement im Formular zu durchlaufen und die Steuerelemente zu deaktivieren.

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

Hinweise

Mit dieser Methode können Sie einen Verweis auf das derzeit aktive Formular abrufen, um Aktionen für das Formular oder dessen Steuerelemente auszuführen.

Wenn Ihre Anwendung eine MDI-Anwendung (Multiple-Document Interface) ist, verwenden Sie die ActiveMdiChild Eigenschaft, um das derzeit aktive untergeordnete MDI-Formular abzurufen.

Gilt für:

Weitere Informationen