In order to do something before the form is closing we can use the next event in the form:
public event FormClosingEventHandler FormClosing
The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form.
The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the FormClosing event:
private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CloseReason", e.CloseReason );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendLine();
messageBox.Show(messageBoxCS.ToString(), "FormClosing Event" );
}
No comments:
Post a Comment