Nazgulled Posted September 8, 2004 Posted September 8, 2004 I have 2 possible ways to close my application, the first one is the close controlbox button of the window form, the second is the Exit option in a menu associated to a systray icon. The code to close the application through the menu in the systray is like this: Me.Close() Application.Exit() Is this the best way to terminate an application? But my main question is how can I use the close controlbox button to hide the form and not terminate the application. then I would use the systray icon to show the form, but that's not really important. The Exit menu option is the only option possible I want to terminate the application, the close controlbox button I want it to perform some code, in this case, to hide the form. Quote
*Experts* DiverDan Posted September 8, 2004 *Experts* Posted September 8, 2004 (edited) Try using the closing base class event. This event is triggered both when the form is closed from the controlbox and, using Me.Close(), from any coded event. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Me.Hide() e.Cancel = True 'keeps the form from closing End Sub I hope this is what you want to do. Edited September 8, 2004 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Nazgulled Posted September 8, 2004 Author Posted September 8, 2004 yep that's what I wanted... but if I do it like that, when I click Exit on the Menu, isn't the Me.Close() unnecessary? cuz it will not close, the application will only terminate with Application.Exit() right? is that enough? Quote
*Experts* DiverDan Posted September 8, 2004 *Experts* Posted September 8, 2004 Or you can put a conditional expression in the closeing event. if blah then me.hide() e.cancel = true else : e.cancel = false end if Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Nazgulled Posted September 8, 2004 Author Posted September 8, 2004 ok thanks... one problem resolved :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.