Q: closing a form

  • Thread starter Thread starter G .Net
  • Start date Start date
G

G .Net

Hi

I'm soooo sorry but I've had to re-post this message again. I have no idea
what has been happening but for some reason I couldn't seem to be able to
see messages that I'd posted earlier.

My question is this - how can I determine if a user clicked the cross in the
top right of the form to close it.

Thanks in advance (and sorry again for re-posting)

Goeff
 
G .Net said:
Hi

I'm soooo sorry but I've had to re-post this message again. I have
no idea what has been happening but for some reason I couldn't seem
to be able to see messages that I'd posted earlier.

My question is this - how can I determine if a user clicked the
cross in the top right of the form to close it.

Thanks in advance (and sorry again for re-posting)


And what if he closes it from the window menu or by pressing Alt+F4 or by
pressing a Close-Button? Does it make a difference?

Maybe you're looking for the Closing or Closed events.


Armin
 
Hi Armin

I think that the events Close and Closing occur whatever way the form has
closed e.g. if there is button with DialogResult Ok then it will still
trigger the above. I need to know the form has been closed by clicking the
cross.

Geoff
 
As far as I know, the .Net framework does not recognise a difference
between the different possible ways of closing a form.

It might not even be possible at a low level to distinguish them - say,
each method just sends a WM_CLOSE message.

However, as Armin indicated, if you could give more information about
why knowing whether the form was closed this way is important, perhaps
someone could suggest another way to achieve your desired result.

hth,
Alan.
 
Hi

Interesting.

I've thought of a way to do it. Basically, I'm going to create a boolean
which will be set to true if some buttons are pressed otherwise it will be
left as false. I can then check the variable in the OnClose event which will
give the functionality I require.

The reason I am trying this is that I want to re-set some global variables
if, for example, a cancel button is pressed.

Geoff
 
G .Net said:
Hi Armin

I think that the events Close and Closing occur whatever way the
form has closed e.g. if there is button with DialogResult Ok then it
will still trigger the above. I need to know the form has been
closed by clicking the cross.


If you're using VB 2005, you could handle the FormClosing event and look at
e.CloseReason.

I still don't know if you want to distinguish between the cross and the
window menu and Alt+F4. If this is all the same and there is only a
difference to the button, then you could evaluate the Dialogresult property,
which is only Dialogresult.Ok if you used the button.


Armin
 
As far as I know, the .Net framework does not recognise a difference
between the different possible ways of closing a form.

It may not know the difference between Alt-F4 and closing the form, but it
can offer some assistance. In the FormClosing event, you can check the CloseReason
property of the event arg for some ideas. It will tell you if the reason
is due to MDIParent closing, OS shutdown, etc. It does not distinguish between
form closing by the user selecting the X, Alt-F4, and me.close() in a btnOk.Click
handler however.

Jim Wooley
http://devauthority.com/blogs/jwoole
 
I'm soooo sorry but I've had to re-post this message again. I have no
idea what has been happening but for some reason I couldn't seem to be
able to see messages that I'd posted earlier.

My question is this - how can I determine if a user clicked the cross
in the top right of the form to close it.

FWIW, you can browse to the original message thread at http://groups.google.com/group/micr...fc?q=Q:closing+a+form&rnum=1#ba0e849bc599d7fc

Jim Wooley
http://devauthority.com/blogs/jwoole
 
Back
Top