Form.ActiveForm Propriété

Définition

Obtient le formulaire actuellement actif pour cette 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; }
member this.ActiveForm : System.Windows.Forms.Form
Public Shared ReadOnly Property ActiveForm As Form

Valeur de propriété

Form

Form représentant le formulaire actuellement actif, ou null si aucun formulaire n'est actif.

Exemples

L’exemple suivant obtient le formulaire actif et désactive tous les contrôles du formulaire. L’exemple utilise la Controls collection du formulaire pour itérer à travers chaque contrôle du formulaire et désactiver les contrôles.

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

Remarques

Vous pouvez utiliser cette méthode pour obtenir une référence au formulaire actif pour effectuer des actions sur le formulaire ou ses contrôles.

Si votre application est une application mDI (multidocument interface), utilisez la ActiveMdiChild propriété pour obtenir le formulaire enfant MDI actif.

S’applique à

Voir aussi