Form.FormClosed Form.FormClosed Form.FormClosed Form.FormClosed Event

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 ejemplo de código siguiente se muestra el uso de este miembro.The following code example demonstrates the use of this member. En el ejemplo, un controlador de eventos informa sobre la aparición de la FormClosed eventos.In the example, an event handler reports on the occurrence of the FormClosed event. Este informe le ayuda a saber cuándo el evento se produce 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 reemplazar MessageBox.Show con Console.WriteLine o agregar el mensaje a un multilínea TextBox.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 ejemplo de código, péguelo en un proyecto que contiene una instancia del tipo Form denominado 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 está asociado el controlador de eventos con el FormClosed eventos.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 FormClosed evento se produce después de que se ha cerrado el formulario por el usuario o por el Close método o la Exit método de la Application clase.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 impedir el cierre del formulario, controlar el FormClosing evento y establecer el Cancel propiedad de la CancelEventArgs pasa al controlador de eventos 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 tales como la liberación de recursos utilizados por el formulario y guardar la información especificada en el formulario o para actualizar su formulario principal.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 principal de la interfaz de múltiples documentos (MDI), el FormClosing se generan eventos de todos los formularios MDI secundarios antes del formulario primario MDI FormClosing provoca el evento.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, el FormClosed se generan eventos de todos los formularios MDI secundarios antes de la FormClosed se provoca el evento 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: