RV.
RV.

Reputation: 2842

closing a window

If I am closing a window I want to know by which way the window gets closed (i.e) by a mouse click in the close icon or alt+f4. Is there any event for getting this info?

Upvotes: 0

Views: 193

Answers (3)

Pontus Gagge
Pontus Gagge

Reputation: 17278

Whether or not you can trap specific WM_...-messages to distinguish between them, don't do it! One of the fundamental pricniples of usability is no suprises: live up to the user's expectations. Do what every other application does, especially when it comes to the absolute basics.

Upvotes: 2

Mihai Limbășan
Mihai Limbășan

Reputation: 67786

No matter which toolkit you're using there are always events for clicks on the close button, keyboard events for Alt+F4, menu click events for menus etc. All you have to do is enumerate the possible ways to quit your application, change the event handlers to set a variable to their corresponding value, and check that variable in your application close procedures.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503260

I don't believe there are any events specifically to give you this information, no. The FormClosingEvent provides a FormClosingEventArgs with a CloseReason, but the reason doesn't distinguish between using a mouse or the keyboard. It only distinguishes between a "user close" event and things like "the form owner closed" or "the application was shut down from task manager."

Upvotes: 2

Related Questions