ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create a Notify Icon in VB.Net

This time, I’m going to make a simple NotifyIcon in VB.NET. This NotifyIcon includes the current date and the kind of operating system (OS) that you are using and It will appear into the system tray of your computer.

 

So, let’s begin:

 
Open the Visual Basic and create a new Windows Form Application. Drag a “ContextMenuStrip”, ”NotifyIcon”, ”Button” and it will look like this.
notifyiconform

 

After that, click the ContextMenuStrip and add the following items into it.
notifyiconform1

After adding the items, double click the “Current Date and Time” to fire the click event handler of it. Set the current date and time in the pop-up message.

  1. Private Sub CurrentDateAndTimeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentDateAndTimeToolStripMenuItem.Click
  2. 'GET THE CURRENT DATE
  3. MsgBox("Today is " & My.Computer.Clock.LocalTime.ToLongDateString & ".")
  4. End Sub

After that, go back to the Form Design and double click the “Operating System (OS) Version” to fire the click event handler of it. Set the current OS version in the pop-up message.

  1. Private Sub OperatingSystemOSToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OperatingSystemOSToolStripMenuItem.Click
  2. 'GET THE CURRENT OPERATING SYSTEM INFORMATION
  3. MsgBox(My.Computer.Info.OSFullName & vbCrLf & "Version " & My.Computer.Info.OSVersion)
  4. End Sub

Go back to the Form Design again and double click the “exit” to fire the click event handler of it. Put this code for closing the application.

  1. Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  2. 'HIDE THE ICON BEFORE CLOSING THE FORM .
  3. NotifyIcon1.Visible = False
  4. ME.CLOSE
  5. End Sub

Go back to the Form Design again, double click the Button and put the code in the click event handler of the Button. This method is for hiding the Form and showing the icon in the system tray.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. 'SET THE NOTIFYICON TO MAKE IT APPEAR INTO THE SYSTEM TRAY
  3. NotifyIcon1.Visible = True
  4. NotifyIcon1.Text = "System Information"
  5. 'HIDDING THE FORM
  6. Me.Hide()
  7. End Sub

Now, double click the NotifyIcon and put this code into the mousedoubleclick event handler of it.

  1. Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
  2. 'WHEN YOU DOUBLE CLICK THE ICON IT WILL DISAPPEAR IN THE SYSTEM TRAY AND THE FORM WILL BE APPEAR.
  3. NotifyIcon1.Visible = False
  4. Me.Show()
  5. End Sub

Finally, hide the notifyIcon on the first load of the Form.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. 'DISAPPEARING THE ICON IN THE SYSTEM TRAY ON THE FIRST LOAD.
  3. NotifyIcon1.Visible = False
  4. Me.Hide()
  5. End Sub

You can download the complete source code.

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!