I just using vb .NET and i'm familiar with vb 6.0 event QueryUnload, but how do you implement the closing event from vb .NET.
Printable View
I just using vb .NET and i'm familiar with vb 6.0 event QueryUnload, but how do you implement the closing event from vb .NET.
The closing event works basically like the Form_Unload event or QueryUnload event but there is no known way to catch the reason the form is closing. .NET doesn't have anything like the UnloadMode in VB6.
the closing event is
Private Sub form1_closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closing
that what you wanted?
J
actually I had the same question a few days ago and I asked it in GotDotNet forums, I couldnt find the answer. But there is a way to do it. This is from MSDN: "If it is necessary to determine why the form is closing, you will need to create an overloaded version of the Closing event with custom code to determine the caller."Quote:
Originally posted by Edneeis
The closing event works basically like the Form_Unload event or QueryUnload event but there is no known way to catch the reason the form is closing. .NET doesn't have anything like the UnloadMode in VB6.
so there is a way:D but I dont know how to overload this thing the way it says it
What MSDN article does that come from? I really miss that feature especially for some TrayIcon apps I have.
i found out a way to get work. In the "Windows Form Designer generated code" the is a dispose function. i put my code there.
I am not sure but, I think this is what you are looking for. It uses the new class messagebox, the old msgbox is still there but it in the Microsoft.VisualBasic namespace. I try to use the SYSTEM namespace first you know onward and upward.
Anyway this works perfect, you can stop the form from closing. The old way was with a byref variable, but we are using objects now.
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim Response As DialogResult
Response = MessageBox.Show("Are you sure you want to Quit?", "Finishing", MsgBoxStyle.YesNo)
If Response = DialogResult.No Then e.Cancel = True
End Sub
related to overloading
Private Sub form1_closing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closing
Overloading lets a function vary its behavior based on its input arguments . vb.net will have multiple functions with the same name, but with different argument lists.
Private Sub form1_closing(ByVal sender As Integer , ByVal e As System.EventArgs) Handles MyBase.Closing (as an example)
How do you get the OS or what not to tell you why the form is closing like the old UnloadMode. For instance was it the x close button in the corner of the form? Was it the Me.Close method in your code? Was it because the OS is shuting down? The last one is really the most important.
well take a lookie at these two, they dont help much, but maybe you can ask them a question so that they could help:DQuote:
Originally posted by Edneeis
How do you get the OS or what not to tell you why the form is closing like the old UnloadMode. For instance was it the x close button in the corner of the form? Was it the Me.Close method in your code? Was it because the OS is shuting down? The last one is really the most important.
http://www.gotdotnet.com/Community/M....aspx?id=40651
and (C# forums):
http://www.gotdotnet.com/Community/M....aspx?id=40717
Well I can detect the X button close and the me.close (I think) but haven't found how to track the System closing. The way I have is somewhat hackish, its easy to implement but not the prettiest. I'll post it when I figure the last one out. Basically you can use the Application.AddMessageFilter to filter Window messages like subclassing. So then I just watch for the NCMouseDown event with wParam 20 which is the mousedown event for the form's close button. If I catch it then I don't forward it instead I call an alternate Closing event and pass the unloadmode in the eventargs.