Form.FormClosed Evento

Definición

Se produce después de haberse cerrado el formulario.Occurs after the form is closed.

public:
 event System::Windows::Forms::FormClosedEventHandler ^ FormClosed;
public event System.Windows.Forms.FormClosedEventHandler FormClosed;
member this.FormClosed : System.Windows.Forms.FormClosedEventHandler 
Public Custom Event FormClosed As FormClosedEventHandler 

Ejemplos

En el siguiente ejemplo se muestra el uso de este miembro.The following example demonstrates the use of this member. En el ejemplo, un controlador de eventos informa sobre la aparición del evento FormClosed.In the example, an event handler reports on the occurrence of the FormClosed event. Este informe le ayuda a saber cuándo se produce el evento y puede ayudarle a depurar.This report helps you to learn when the event occurs and can assist you in debugging. Para informar sobre varios eventos o en eventos que se producen con frecuencia, considere la posibilidad de reemplazar MessageBox.Show por Console.WriteLine o anexar el mensaje a un TextBox multilínea.To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

Para ejecutar el código de ejemplo, péguelo en un proyecto que contenga una instancia de tipo Form denominada Form1.To run the example code, paste it into a project that contains an instance of type Form named Form1. A continuación, asegúrese de que el controlador de eventos está asociado al evento FormClosed.Then ensure that the event handler is associated with the FormClosed event.

private void Form1_FormClosed(Object sender, FormClosedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "FormClosed Event" );
}
Private Sub Form1_FormClosed(sender as Object, e as FormClosedEventArgs) _ 
     Handles Form1.FormClosed

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"FormClosed Event")

End Sub

Comentarios

El evento FormClosed se produce después de que el usuario haya cerrado el formulario o por el método Close o el método Exit de la clase Application.The FormClosed event occurs after the form has been closed by the user or by the Close method or the Exit method of the Application class. Para evitar que un formulario se cierre, controle el evento FormClosing y establezca la propiedad Cancel del CancelEventArgs que se pasa al controlador de eventos a true.To prevent a form from closing, handle the FormClosing event and set the Cancel property of the CancelEventArgs passed to your event handler to true.

Puede usar este evento para realizar tareas como liberar recursos utilizados por el formulario y guardar información especificada en el formulario o actualizar su formulario primario.You can use this event to perform tasks such as freeing resources used by the form and to save information entered in the form or to update its parent form.

Si el formulario es un formulario MDI (interfaz de múltiples documentos) primario, se generan los eventos FormClosing de todos los formularios MDI secundarios antes de que se genere el evento FormClosing del formulario MDI primario.If the form is a multiple-document interface (MDI) parent form, the FormClosing events of all MDI child forms are raised before the MDI parent form's FormClosing event is raised. Del mismo modo, los eventos FormClosed de todos los formularios MDI secundarios se generan antes de que se produzca el evento FormClosed del formulario primario MDI.Likewise, the FormClosed events of all MDI child forms are raised before the FormClosed event of the MDI parent form is raised.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.For more information about handling events, see Handling and Raising Events.

Se aplica a

Consulte también: