How to test windows form is closed by user's clicking on the "x"

  • Thread starter Thread starter feng
  • Start date Start date
F

feng

I need to test if the form is closing because of user's
clicking on the "x" button, instead of other buttons, such
as my "Exit" button, on my form.

I would like to test this in my form's Closing event
handler, but I don't know how to do this.

Can someone show me how?

Thanks.
 
Hi Feng,

When I want to know this kind of things and I do not know the solution I do
not look very long.

I set a global (private) bool/switch/status whatever you want and do on my
close-button and the others events something as closeSwitch = true

Than I test in the closing event on that closeSwitch and I know.

Cor
 
Use the QueryUnload event routine to take whatever action you want
when the user closes the form by clicking the "X" button on the form.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

every form has this event handler--read the VB help file for the
QueryUnload event.
 
Hi Tom,

Become I crazy, just a switch to test in the closing event and than you know
it.

What do I mis?

Cor
 
Hi Cor,

I saw your reply the other day and it sounds fine to me. I guess there are
several ways the window could be being told to close however. If you want
to handle things differently a bunch of flags might not be as handy. I
really don't know.

Tom
 
Back
Top