How to Create a Simple NotifyIcon in Visual Basic 2008
Submitted by janobe on Tuesday, May 13, 2014 - 10:55.
In this tutorial I will teach you how to create a simple NotifyIcon by using Visual Basic 2008. This NotifyIcon contains the system information that allows you to know the current date and the kind of operating system (OS) that you are using.
So let’s begin:
Open Visual Basic 2008 and create a new Windows Application. Drag a “ContextMenuStrip”, ”NotifyIcon”, ”Button” and “Label”. And do, the Form just like this.
After that click the ContextMenuStrip and add the items on it which are the “Current Date”, “OS Version” and “Exit”. Then, it will look like this.
Double click the “Current Date” in the ContextMenuStrip and do this following code for getting the current date of the system.
After that, do this following code for getting the current OS version.
Then, do this following code for the Exit.
After that, Do this following code for hiding the Form and showing the icon in the system tray.
Do this following code for the
Lastly, do this following code on the first load for showing the current date and OS version in the Form.
Output :
- Private Sub CurrentDateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentDateToolStripMenuItem.Click
- 'GET THE CURRENT DATE
- End Sub
- Private Sub OSVersionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OSVersionToolStripMenuItem.Click
- 'GET THE CURRENT OPERATING SYSTEM INFORMATION
- End Sub
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- 'HIDE THE ICON FIRST BEFORE YOU CLOSE THE APPLICATION
- 'BECAUSE IT CANNOT BE SEEN ONCE THE APPLICATION IS CLOSED.
- NotifyIcon1.Visible = False
- Application.Exit()
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- 'HIDE THE FORM AND VISIBLE THE NOTIFYICON SO THAT IT WIIL APPEAR IN THE SYSTEM TRAY
- Me.Hide()
- NotifyIcon1.Visible = True
- NotifyIcon1.Text = "System Information"
- End Sub
doubleclick
event of the NotifyIcon.
- Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
- 'WHEN YOU DOUBLE CLICK THE ICON IT WILL DISAPPEAR AND THE FORM WILL BE SHOWN.
- NotifyIcon1.Visible = False
- Me.Show()
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'HIDING THE ICON ON THE FIRST LOAD OF THE FORM
- 'SO THAT IT WILL NOT APPEAR IN THE SYSTEM TRAY
- NotifyIcon1.Visible = False
- 'SETS THE CURRENT DATE AND OS VERSION IN THE LABEL
- lblCurtime.Text = "Today's date is " & My.Computer.Clock.LocalTime.ToLongDateString & "."
- lblCurOS.Text = My.Computer.Info.OSFullName & vbCrLf & "Version " & My.Computer.Info.OSVersion
- End Sub
Add new comment
- 159 views