0

In the FormClosing event handler of a Windows Form, I want to detect if the event is from a programmatically Form.Close() method call or through a user action in the user interface (for example, by clicking the Close button [X] on the form window).

I must show a dialog to confirm with the user whether he/she really wants to exit the application only if the FormClosing event is through a user clicking [X] button.

Is it possible? If yes, how to do?

Thanks you all in advance.

Johnson
  • 157
  • 3
  • 17
  • A User cannot call `Form.Close()`, you can, so you also can set a flag (or just the Tag property of the Form that's about to close). – Jimi Aug 11 '21 at 07:53
  • Anyway, check this answer: [How to know user has clicked “X” or the “Close” button?](https://stackoverflow.com/a/58790227/7444103) (the one I linked, not the accepted answer, which is completely wrong) – Jimi Aug 11 '21 at 07:59

0 Answers0