Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Minimizing to System Tray
 

Minimizing to System Tray

    Private Sub mnuMinimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMinimize.Click
        Me.Hide()
    End Sub

(that "minimizes" to the system tray by hiding the form)

how do i go about adding the program icon to the system tray once minimized and adding menu options for the icon so i can restore it or exit from there, etc.
c0ke  Wednesday, March 29, 2006 9:56 PM

me.hide wont put the application in the system tray but will show in the taskbar if the form showintaskbar property is true.

If this is what you want then setting the icon for the form should change the icon being show.

If your really talking about the system tray and using this then the following article should get you going.

http://www.startvbdotnet.com/controls/notifyicon.aspx

http://www.vb-helper.com/howto_net_tray_icon.html

http://www.codeguru.com/columns/VB/article.php/c6547/

spotty  Wednesday, March 29, 2006 10:44 PM

me.hide wont put the application in the system tray but will show in the taskbar if the form showintaskbar property is true.

If this is what you want then setting the icon for the form should change the icon being show.

If your really talking about the system tray and using this then the following article should get you going.

http://www.startvbdotnet.com/controls/notifyicon.aspx

http://www.vb-helper.com/howto_net_tray_icon.html

http://www.codeguru.com/columns/VB/article.php/c6547/

spotty  Wednesday, March 29, 2006 10:44 PM

A simple solution, once you see it. Create the following, then add the code to your form.

A ToolStripMenuItem named "TrayToolStripMenuItem", inside of

A ContextMenuStrip named "TrayMenuStrip", inside of

A NotifyIcon named "TrayIcon":

Private Sub TrayIcon_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrayIcon.MouseDown

Select Case Me.WindowState

Case FormWindowState.Minimized

TrayToolStripMenuItem.Text = "Show"

Case FormWindowState.Normal

TrayToolStripMenuItem.Text = "Hide"

Case FormWindowState.Maximized

TrayToolStripMenuItem.Text = "Hide"

End Select

End Sub

Private Sub TrayIcon_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrayIcon.MouseDoubleClick

If Me.WindowState = FormWindowState.Minimized Then

Me.Show()

Me.WindowState = FormWindowState.Normal

Else

Me.WindowState = FormWindowState.Minimized

Me.Hide()

End If

End Sub

Private Sub TrayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayToolStripMenuItem.Click

If Me.WindowState = FormWindowState.Minimized Then

Me.Show()

Me.WindowState = FormWindowState.Normal

Else

Me.WindowState = FormWindowState.Minimized

Me.Hide()

End If

End Sub

sp00k113  Monday, March 05, 2007 4:04 AM

You can use google to search for other answers

Custom Search

More Threads

• PathName in Shell function with arguments and command-line switches
• ToolStrip Button Menu Help!!!!!
• VB forms issue - driving me crazy ...
• Please Help, Vista - System.Security.SecurityException Issue
• Help with ChangeDisplaySettingsEx Function to Attach a Secondary Monitor (Conversion C to VB)
• Application bar
• Question and help
• Exit Button Removal
• Create a rounded off rectangle
• Is there a better way to do this