Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a class with a Shared Sub Main() that starts things off. It shows a menu then when the user clicks the exit button it "should" minimize to system tray. It does minimize to system tray, but as soon as it does the app closes too. This is basically what I have in the Sub Main().

Public Class Main

   Public Shared Sub Main()

       Dim frmMenu As New VATMenu()

       Application.Run(frmMenu)

   End Sub

End Class

 

I was going to do a search on this topic, but didn't really know what to search for. Basically I need to know how to keep my app alive when it gets to the End Sub. TIA.

  • *Experts*
Posted
You cant keep it running if it gets to End Sub. Are you modiyfing the Closing event of your from so it minimizes when closing as you say?
Posted
You cant keep it running if it gets to End Sub. Are you modiyfing the Closing event of your from so it minizes when closing as you say?

 

Yes I am on the frmMenu_Closing. I believe that is where it closing the project at. Here is the code I have for that procedure.

 

   Private Sub me_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

       Dim frm1 As New Form1()
       xLoc = Me.Location.X
       yLoc = Me.Location.Y
       exitQuestion = MsgBox("Are you sure you want to exit the VAT's menu?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm Exit")
       If exitQuestion = vbNo Then
           Me.Location = New Point(xLoc, yLoc)
           Me.StartPosition = FormStartPosition.Manual
           Me.Show()
       ElseIf exitQuestion = vbYes Then
           exitQuestion = MsgBox("Do you want to minimize menu to the system tray?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Minimize to Tray")
           If exitQuestion = vbNo Then
               frm1 = New Form1()
               Me.Visible = False
               frm1.RemoveIcon()
               frm1.Visible = False
               frm1.RemoveIcon()
           Else
               Me.Show()
           End If
       End If
   End Sub

 

frm1 is of course the tray icon.

  • *Experts*
Posted

You need to cancel the closing of the form, even though you put code in the event it still will close after executing that code unless you stop it:

e.Cancel = True

This goes into your closing event wherever you want to stop the form from closing.

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...