Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted (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 by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
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?
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...