How capture when user clicks X in top right corner?

R

Ronald S. Cook

In my Windows app, users are clicking on the "X" in the top left corner
instead of clicking File.. Exit. I have code that needs to run prior to the
app shutting down. How can I capture the event when the user clicks the X?

Thanks
Ron
 
M

Marina Levit [MVP]

You would have to handle the Closing or Closed events for the form, which is
not the same. However, there are other ways to close the form other then
clicking close. Like, clicking on the icon in the upper left hand corner and
selecting Close, or right clickign on the app in the taskbard, and clicking
close.

Make sure the handlers of these events know if the user chose Close off the
file menu, or not. If not, then presumably, you want this code to run. Just
wanted to point out it's not literally about clicking the X.
 
M

Markus Stoeger

Ronald said:
In my Windows app, users are clicking on the "X" in the top left corner
instead of clicking File.. Exit. I have code that needs to run prior to the
app shutting down. How can I capture the event when the user clicks the X?

override the OnClosing method in your Form.

hth,
Max
 

Ask a Question

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.

Ask a Question

Top