Couldn´t you just define a variable userClose or something like that
and set it to true if the user presses the close button? In the OnClose event
you then just query the variable and can through this determine if the user
shuts the program down or the system.
The only problem is if you allow the user to press the x in the upper right corner.
At the moment the only thing I could imagine is to analyse the mouse coordinates
and if the mouse is hovering above the x and a click occurs, set the variable to true.
Take a look at Microsoft.Win32.SystemEvents.SessionEnding event
documentation. You should pay particular attention to the remarks about how
to ensure this event firing before System.Windows.Forms.Form.Closing event.
When I mentioned the close button I was referring to the "x" next to
the min and max icons. I probably should have said close control.
Ideally I would like to bind my own handler to the close control, but
I don't know if that is possible.
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.