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

定义

关闭窗体后发生。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 

示例

下面的示例演示如何使用此成员。The following example demonstrates the use of this member. 在此示例中,事件处理程序报告 @no__t 的事件发生。In the example, an event handler reports on the occurrence of the FormClosed event. 此报表可帮助你了解何时发生事件,并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件,请考虑将 @no__t 0 替换为 Console.WriteLine,或将消息附加到多行 TextBoxTo 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.

若要运行示例代码,请将其粘贴到包含名为 @no__t Form 类型实例的项目中。To run the example code, paste it into a project that contains an instance of type Form named Form1. 然后,确保事件处理程序与 @no__t 0 事件关联。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

注解

在用户关闭窗体或 Close 方法或 @no__t 3 类的 Exit 方法之后,将发生 FormClosed 事件。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. 若要防止窗体关闭,请处理 FormClosing 事件,并将传递给事件处理程序的 @no__t 的 @no__t 属性设置为 trueTo prevent a form from closing, handle the FormClosing event and set the Cancel property of the CancelEventArgs passed to your event handler to true.

您可以使用此事件来执行任务,例如释放窗体使用的资源,并保存在窗体中输入的信息或更新其父窗体。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.

如果窗体为多文档界面(MDI)父窗体,则在引发 MDI 父窗体的 @no__t 1 事件之前,将引发所有 MDI 子窗体的 FormClosing 事件。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. 同样,在引发 MDI 父窗体的 @no__t 1 事件之前,将引发所有 MDI 子窗体的 @no__t 0 事件。Likewise, the FormClosed events of all MDI child forms are raised before the FormClosed event of the MDI parent form is raised.

有关处理事件的详细信息,请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

适用于

另请参阅