Form.ActiveForm Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene il modulo attualmente attivo per l'applicazione.
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
Valore della proprietà
Oggetto Form che rappresenta il modulo attualmente attivo o null se non è presente alcun modulo attivo.
Esempio
Nell'esempio seguente viene recuperata la maschera attiva e vengono disabilitati tutti i controlli del modulo. Nell'esempio viene utilizzata l'insieme Controls del form per scorrere ogni controllo nel form e disabilitare i controlli.
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
Commenti
È possibile utilizzare questo metodo per ottenere un riferimento al form attualmente attivo per eseguire azioni sul form o sui relativi controlli.
Se l'applicazione è un'applicazione MDI (Multiple Document Interface), usare la ActiveMdiChild proprietà per ottenere il modulo figlio MDI attualmente attivo.