A Simple Program for Status Bar Notification using Whidbey






1.52/5 (7 votes)
May 10, 2004
1 min read

52551

1602
The NotifyIcon Component will display an icon in the status bar notification area, which you can use as notiification purpose to alert users that an action or event has occured.
Introduction
The NotifyIcon component will display an icon in the status bar notification area, which you can use as notification purpose to alert users that an action or event has occured. You can write code in the Click or DoubleClick event handler or any of the event handler you like to associate your application.
Steps to Create the NotifyIcon application
1. Start a new project and save as “NotifyIcon”.
2. Save the Form1.vb as frmNotifyIcon.vb
3. Double click on the frmNotifyIcon.vb to load the form from the Solution Explorer bar.
4. Drag and Drop the Component NotifyIcon from the toolbox.
Note: Context Menu will be displayed on the bottom of the current form
5. Make new menu items as shown below
6. Change the name of menu item as shown below:
mnuMicrosoftHome
mnuMicrosoftASPNet
mnuMicrosoftWindowsFormNet
mnuMSDN
mnuMSNBC
mnuMSN
7. Add a new procedure called SelectLink.
Private Sub SelectLink(ByVal strMicrosoftWebSiteName As String) Dim strWebSiteName As String Try Select Case strDescription Case "mnuMicrosoftHome" : strWebSiteName = "http://www.microsoft.com/" Case "mnuMicrosoftASPNet" : strWebSiteName = "http://www.asp.net/" Case "mnuMicrosoftWindowsFormNet" : strWebSiteName = "http://www.windowsforms.net/" Case "mnuMSDN" : strWebSiteName = "http://www.msdn.microsoft.com/" Case "mnuMSNBC" : strWebSiteName = "http://www.msnbc.com/" Case "mnuMSN" : strWebSiteName = "http://www.msn.com/" End Select ' Call the Process.Start method to open the default browser ' with a URL: System.Diagnostics.Process.Start(strWebSiteName) Catch ex As Exception ' The error message Beep() MessageBox.Show("Unable to open link " & strDescription & " that was clicked.") End Try End Sub7. Call the selectlink procedure in each click event of menu item.
Private Sub mnuMicrosoftHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMicrosoftHome.Click SelectLinkClick(mnuMicrosoftHome.Text) End Sub Private Sub mnuMicrosoftASPNet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMicrosoftASPNet.Click SelectLinkClick(mnuMicrosoftASPNet.Text) End Sub Private Sub mnuMicrosoftWindowsFormNet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMicrosoftWindowsFormNet.Click SelectLinkClick(mnuMicrosoftWindowsFormNet.Text) End Sub Private Sub mnuMSDN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMSDN.Click SelectLinkClick(mnuMSDN.Text) End Sub Private Sub mnuMSN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMSN.Click SelectLinkClick(mnuMSN.Text) End Sub Private Sub mnuMSNBC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuMSNBC.Click SelectLinkClick(mnuMSNBC.Text) End Sub8. Add the NotifyIcon component from the toolbox.
9. Add the following lines of code in the Form_Load event.
Private Sub frmNotifyIcon_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Visible = False NotifyIcon1.Visible = True End Sub10. Rename the menu name ContextMenu1.
11. Make the project and see how it works!
Requirements
Microsoft Visual Studio.Whidbey Ver 8.0 Or
Microsoft Visual Studio.NET Professional or greater.
Windows 2000 or Windows XP.
Summary:
This is a small program, which will helps you to understand how the NotifyIcon component works. In VB 6.0, we have to do a lot of stuffs to get this icon. This easily simplifies in .NET.
If you need any suggestions or help, let me contact at benoyraj@yahoo.com
Thank you
Benoyraj