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 code example demonstrates the use of this member. 在示例中,事件处理程序报告的匹配项FormClosed事件。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. 若要报告或频繁发生的事件上多个事件,请考虑更换MessageBox.ShowConsole.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.

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

注解

FormClosed事件发生在由用户或通过关闭窗体之后Close方法或Exit方法的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. 若要阻止关闭窗体,处理FormClosing事件并设置Cancel的属性CancelEventArgs传递给事件处理程序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) 父窗体FormClosingMDI 父窗体之前引发事件的所有 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. 同样,FormClosed之前,将引发事件的所有 MDI 子窗体FormClosed引发 MDI 父窗体。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.

适用于

另请参阅