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

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
----- 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
 
* "=?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>
 
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
 
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
 
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
 
* "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>
 
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
 
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 :)
 
Back
Top