469,646 Members | 1,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

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

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.
Nov 20 '05 #1
7 1275
Cor
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
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?

Nov 20 '05 #2
* "feng" <an*******@discussions.microsoft.com> scripsit:
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.


Determine a Form's UnloadMode
<http://www.fawcette.com/archives/premier/mgznarch/vbpj/2001/11nov01/qa0111/qa0111.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
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.
On Sat, 14 Feb 2004 23:13:49 -0800, "feng"
<an*******@discussions.microsoft.com> wrote:
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.


Nov 20 '05 #4
"James Gray" <ji*****@quik.com> schrieb
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.


The event does not exist.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
To the OP...

There is a discussion here:
http://www.gotdotnet.com/Community/M....aspx?id=40651

Perhaps that can be of help,
Tom

"Armin Zingler" <az*******@freenet.de> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
"James Gray" <ji*****@quik.com> schrieb
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.


The event does not exist.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
Cor
Hi Tom,

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

What do I mis?

Cor

Nov 20 '05 #7
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

"Cor" <no*@non.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi Tom,

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

What do I mis?

Cor

Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Bradbury | last post: by
10 posts views Thread by universalbitmapper | last post: by
5 posts views Thread by Stefano Tonello | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.