Q: How to differentiate onClose via system shutdown vs via control box?

  • Thread starter Thread starter brewman
  • Start date Start date
B

brewman

How can you tell if an onClosing event were raised as a result of the
user clicking on the close control vs a system shutdown?

TIA
 
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.

Hope this helps.
Greetings, timtos.
 
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.

Hope this helps.
 
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.
 
Back
Top