0

Hey, I would like to show a prompt when a user clicks on the "X" button on my form, but it doesn't seem to be working.. Here is the code:

private void Form_FormClosing(object sender, FormClosedEventArgs e)
{
   if (e.CloseReason == CloseReason.UserClosing)
      {
         MessageBox.Show("YES");
      }
}

Any ideas?

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by abelLazm
0

Code works fine here, message box shows, form closes, everyone is happy. Did you attach the method to the FormClosing event?

You can try putting a MessageBox as the first line just to see if the event is firing.

0

Yeah, that is so weird..

I have a login form (subform) and I don't want users just to be able to click on the X button and still be able to access the content..

Thanks for your reply

0

Are you writing this code in the main form or in the subform? and what is the exception you are getting because I am using this event in my application i have added quite a large lines of code in it and it works fine..... Try

System.Windows.Forms.FormClosingEventArgs

instead of

FormClosedEventArgs
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.