Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / MFC
Article

A Simple Program for Status Bar Notification using Whidbey

Rate me:
Please Sign up or sign in to vote.
1.52/5 (7 votes)
9 May 20041 min read 52.2K   1.6K   20   3
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.

Sample Image - StatusBar.jpg

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

NotifyIcon project


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.


NotifyIcon Image 2

Note: Context Menu will be displayed on the bottom of the current form

NotifyIcon Image - 3

5. Make new menu items as shown below

Image 4 : NotifyIcon

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 = "<A href="http://www.microsoft.com/">http://www.microsoft.com/</A>"
              Case "mnuMicrosoftASPNet" : strWebSiteName = "<A href="http://www.asp.net/">http://www.asp.net/</A>"
              Case "mnuMicrosoftWindowsFormNet" : strWebSiteName = "<A href="http://www.windowsforms.net/">http://www.windowsforms.net/</A>"
              Case "mnuMSDN" : strWebSiteName = "<A href="http://www.msdn.microsoft.com/">http://www.msdn.microsoft.com/</A>"
              Case "mnuMSNBC" : strWebSiteName = "<A href="http://www.msnbc.com/">http://www.msnbc.com/</A>"
              Case "mnuMSN" : strWebSiteName = "<A href="http://www.msn.com/">http://www.msn.com/</A>"
          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 Sub

7. 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 Sub

8. Add the NotifyIcon component from the toolbox.

Image 5 - NotifyIcon

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 Sub

10. Rename the menu name ContextMenu1.

Image 6 - NotifyIcon

11. Make the project and see how it works!

StatusBar Output Image - 1/2

NotifyIcon - Output 2

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
Binoy is a software developer of Information Technology Division in Memphis,TN.

Comments and Discussions

 
QuestionQuestion Pin
timnboys21-Jan-10 10:49
timnboys21-Jan-10 10:49 
GeneralThis is VB.NET... Pin
Ray Hayes10-May-04 8:59
Ray Hayes10-May-04 8:59 
GeneralRe: This is VB.NET... Pin
Binoy R11-May-04 2:25
Binoy R11-May-04 2:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.