Form.ActiveForm Właściwość

Definicja

Pobiera obecnie aktywny formularz dla tej aplikacji.

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

Wartość właściwości

Form

Element Form reprezentujący aktualnie aktywny formularz lub null jeśli nie ma aktywnego formularza.

Przykłady

Poniższy przykład pobiera aktywny formularz i wyłącza wszystkie kontrolki w formularzu. W przykładzie użyto Controls kolekcji formularza, aby iterować każdą kontrolkę w formularzu i wyłączyć kontrolki.

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

Uwagi

Ta metoda umożliwia uzyskanie odwołania do aktualnie aktywnego formularza w celu wykonywania akcji na formularzu lub jego kontrolkach.

Jeśli aplikacja jest aplikacją interfejsu wielodokumentowego (MDI), użyj ActiveMdiChild właściwości , aby uzyskać obecnie aktywny formularz podrzędny MDI.

Dotyczy

Zobacz też