FormClosing event doesn't work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to make the FormClosing event work but nothing is happening. I
have a simple forms app with one form. When I click the X in the top right
corner it seems the Formclosing event is not firing. I first tried to run my
own messagebox, then copied code from
http://msdn2.microsoft.com/en-US/library/system.windows.forms.form.formclosing.aspx and it's not working. Is there something else I need to do?


private void frm2085_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");
//MessageBox.Show("close event fired");
//Cleanup(true, true);
}
 
archuleta37 said:
I'm trying to make the FormClosing event work but nothing is happening. I
have a simple forms app with one form. When I click the X in the top right
corner it seems the Formclosing event is not firing. I first tried to run my
own messagebox, then copied code from
http://msdn2.microsoft.com/en-US/library/system.windows.forms.form.formclosing.aspx and it's not working. Is there something else I need to do?


private void frm2085_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");
//MessageBox.Show("close event fired");
//Cleanup(true, true);
}

Have you wired up the FormClosing event of your form to this method?
Open the form designer and then click on the form. In the Properties
Windows, click the little lightning bolt icon. Then find the
FormClosing event. Is your method selected there? If not select it.
Then it should work.
 
Back
Top