10

I would like to create a program to run from the bottom right system tray of Windows.

But I don't know where to start from?

Can someone tell \ show me where to look and examples or what commands to use \ research ?

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Pavle Stojanovic
  • 525
  • 2
  • 8
  • 30
  • 2
    look at this http://stackoverflow.com/a/1732294/351383, it's C# but if you have problems you can translate it to VB.NET here http://converter.telerik.com/ – Antonio Bakula Aug 07 '13 at 10:06
  • 4
    Google is really useful - a search for "VB.NET program to run from system tray" returned [Create a System Tray Application in VB.NET](http://www.codeproject.com/Articles/75822/Create-a-System-Tray-Application-in-VB-NET). And Visual Basic is **NOT** the same thing as VB.NET. – Tim Aug 07 '13 at 10:07
  • Thanks Guys for youre feedback I'll do some reading now :) – Pavle Stojanovic Aug 07 '13 at 10:13

3 Answers3

19

Add a NotifyIcon to the main windows form. Use the Resize event in Form to control when to show the NotifyIcon and hide the form:

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
                NotifyIcon1.Visible = true
                Me.Hide()
                NotifyIcon1.BalloonTipText = "Hi from right system tray"
                NotifyIcon1.ShowBalloonTip(500)
        End If
    End Sub

Use the events in NotifyIcon to show the form again:

Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
        Me.Show()
        Me.WindowState = FormWindowState.Normal
        NotifyIcon1.Visible = False
    End Sub

You can download a full example in AutoDNIE google code project

jlvaquero
  • 8,571
  • 1
  • 29
  • 45
  • Thanks Guys I will give it a go when I can – Pavle Stojanovic Aug 13 '13 at 00:11
  • 3
    Thanks worked great!! Just don't do what I did and try using it without an icon... it won't work. – DanBarber Feb 14 '16 at 23:07
  • thanks @DanBarber for the tip. for those who don't know where to add icon. go to your **notify icon** component in design and in **properties** window set an .ico file. I didn't know what he meant at first until I tried the above code. – Kym NT Oct 27 '20 at 03:08
14

I review the answers I note that miss the icon.

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        NotifyIcon1.Visible = True
        NotifyIcon1.Icon = SystemIcons.Application
        NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
        NotifyIcon1.BalloonTipTitle = "Verificador corriendo"
        NotifyIcon1.BalloonTipText = "Verificador corriendo"
        NotifyIcon1.ShowBalloonTip(50000)
        'Me.Hide()
        ShowInTaskbar = False
    End If
End Sub

Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
    'Me.Show()
    ShowInTaskbar = True
    Me.WindowState = FormWindowState.Normal
    NotifyIcon1.Visible = False
End Sub
Doberon
  • 611
  • 9
  • 19
1

You can also do:

Sub ToggleHide()
    If Me.WindowState = FormWindowState.Normal Then
        Me.ShowInTaskbar = False
        Me.WindowState = FormWindowState.Minimized
    Else
        Me.ShowInTaskbar = True
        Me.WindowState = FormWindowState.Normal
    End If
End Sub
Rob
  • 46
  • 1
  • 5