FormClosing event doesn't work

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);
}
 
C

Chris Dunaway

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top