How to find out if a user is closing the Form or if it coming from within the Application ?

G

Guest

There is a program in VB , in which, there is a

Form_QueryUnload( Cancel as Integer, UnloadMode as Integer)

which would be called when the form is being closed. The UnloadMode is used to find out if the Fomr is being closed by the user - in which case this event is to be cancelled - and if it is coming from within the application, then it would close the application.
In .NET, the equivalent Function is

Form_Closing(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

in which the 'Cancel' Equivalent in the above VB function exists, but not the 'UnloadMode'. What i wanted to know is, how do i now find out if the Form s being closed by the user, or if it is coming from with in the application ?

Thanks in advance.
 
C

Cor

Hi Bande,

I always had the same problems as you.

Now I use the "MyBase.Closing" event
I have no problems anymore with it,

But I don't know if it is because my knowledge of VB.net is improved or that
it is because I use 2003 and Net 1.1 now, because in past, I was always
strugling with it.

Cor
 
G

Guest

----- Cor wrote: -----

Hi Bande,

I always had the same problems as you.

Now I use the "MyBase.Closing" event
I have no problems anymore with it,

But I don't know if it is because my knowledge of VB.net is improved or that
it is because I use 2003 and Net 1.1 now, because in past, I was always
strugling with it.

Cor


hi,
Can you please tell me how you used the "MyBase.Closing" Event ?

Bande
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?QmFuZGU=?= said:
Form_Closing(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

in which the 'Cancel' Equivalent in the above VB function exists, but not the 'UnloadMode'. What i wanted to know is, how do i now find out if the Form s being closed by the user, or if it is coming from with in the application ?

Set a flag before closing the application by code. Then you can check
this flag.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
C

Cor

Hi Bande,

I was searching for the answer, then I saw Herfried wrote it already.
A flag like he calls it, is called by others a switch or a boolean.

Cor
 
C

Cor

I was searching for the answer, then I saw Herfried wrote it already.
Someone made almost this correction on a message from me too yesterday. And
I was busy writing almost the same message as you did (because I did want
to be sure the Alt F4 was not trappable on an easier way when I saw your
message. So I changed it in this way. Not everybody knows what is the
meaning of a flag, or a switch or a boolean, like a lot of people use.

Cor
 
C

Cor

Hi Herried,
I had to clean my glasses. I thought you was sending a question mark. Saw it
was not and thought I deleted the message, wrong button.
Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Someone made almost this correction on a message from me too yesterday. And
I was busy writing almost the same message as you did (because I did want
to be sure the Alt F4 was not trappable on an easier way when I saw your
message. So I changed it in this way. Not everybody knows what is the
meaning of a flag, or a switch or a boolean, like a lot of people use.

I will include all three words in future posts.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
T

Tom Shelton

There is a program in VB , in which, there is a

Form_QueryUnload( Cancel as Integer, UnloadMode as Integer)

which would be called when the form is being closed. The UnloadMode is used to find out if the Fomr is being closed by the user - in which case this event is to be cancelled - and if it is coming from within the application, then it would close the application.
In .NET, the equivalent Function is

Form_Closing(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

in which the 'Cancel' Equivalent in the above VB function exists, but not the 'UnloadMode'. What i wanted to know is, how do i now find out if the Form s being closed by the user, or if it is coming from with in the application ?

Thanks in advance.

Here is another alternative....

http://www.ftponline.com/Archives/premier/mgznarch/vbpj/2001/11nov01/qa0111/qa0111.asp

You'll want to scroll down till you see the Question - Determine a
Form's UnloadMode.

HTH
 
Joined
Jan 15, 2013
Messages
1
Reaction score
0
I know this is now an ancient thread, but in case anyone else is looking for a solution (VS2010) then use "CloseReason"

3 is the form being closed by the user, and 6 is as the result of an application crash.

Hope this is useful to someone :)
 

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