Form.ActiveForm Form.ActiveForm Form.ActiveForm Form.ActiveForm Property

Definición

Obtiene el formulario que está activo para esta aplicación.Gets the currently active form for this application.

public:
 static property System::Windows::Forms::Form ^ ActiveForm { System::Windows::Forms::Form ^ get(); };
public static System.Windows.Forms.Form ActiveForm { get; }
member this.ActiveForm : System.Windows.Forms.Form
Public Shared ReadOnly Property ActiveForm As Form

Valor de propiedad

Form que representa el formulario que está activo o null si no hay ningún formulario activo.A Form that represents the currently active form, or null if there is no active form.

Ejemplos

En el ejemplo de código siguiente se obtiene el formulario activo y se deshabilitan todos los controles del formulario.The following code example gets the active form and disables all the controls on the form. En el ejemplo se Controls utiliza la colección del formulario para recorrer en iteración cada control del formulario y deshabilitar los controles.The example uses the Controls collection of the form to iterate through each control on the form and disable the 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 'DisableActiveFormControls

Comentarios

Puede utilizar este método para obtener una referencia al formulario actualmente activo para realizar acciones en el formulario o en sus controles.You can use this method to obtain a reference to the currently active form to perform actions on the form or its controls.

Si la aplicación es una aplicación de interfaz de múltiples documentos (MDI), use ActiveMdiChild la propiedad para obtener el formulario MDI secundario actualmente activo.If your application is a multiple-document interface (MDI) application, use the ActiveMdiChild property to obtain the currently active MDI child form.

Seguridad

UIPermission
para solicitar un formulario.for requesting a form. Enumeración asociada: AllWindows.Associated enumeration: AllWindows.

Se aplica a

Consulte también: