Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Visual Basic NotifyIcon for Taskbar Notification

, 17 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Taskbar notifications give nice touch to user interface design. Visual Basic NotifyIcon is the right control to implement taskbar notifications. To begin with, Place a NotifyIcon control on your Form1 …The post Visual Basic NotifyIcon for Taskbar Notification appeared first on Bubble Blog.

Taskbar notifications give nice touch to user interface design. Visual Basic NotifyIcon is the right control to implement taskbar notifications.

To begin with, Place a NotifyIcon control on your Form1 Design. Click Choose Icon and select any icon file for it

NotifyIconPaste following code in Windows Application1 :

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        NotifyIcon1.BalloonTipText = "Tool Tip Text for Windows Application"
        NotifyIcon1.Text = "Windows Application"
        NotifyIcon1.ShowBalloonTip(5000)
        CreateContextMenu()

    End Sub

    Public Sub CreateContextMenu()

        'Define New Context Menu and Menu Item 
        Dim contextMenu As New ContextMenu
        Dim menuItem As New MenuItem("Exit")
        contextMenu.MenuItems.Add(menuItem)

        ' Associate context menu with Notify Icon 
        NotifyIcon1.ContextMenu = contextMenu

        'Add functionality for menu Item click 
        AddHandler menuItem.Click, AddressOf menuItem_Click

    End Sub

    Private Sub menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

End Class

Press F5 to run the application. At start of the application, we can see the balloon tip notification text. Context Menu is also working with an Exit option.

NotifyIcon

NotifyIcon ToolTipText is shown

NotifyIcon

NotifyIcon Text is visible when mouse is hovered

NotifyIcon

NotifyIcon Context Menu option

Code Description for NotifyIcon

  • It is necessary to define the BalloonTipText before calling to show the BalloonTip. At form load, we define the desired texts for Notify Icon and balloon tip notification
  • CreateMenu() method defines the context menu functionality for the Notify Icon. It is easy to understand the code with inline comments. Please have a look at our detailed post on Visual Basic Drop Down Menu for additional guidance
  • menuItem_Click() provides functionality when Exit option is selected from the Context Menu.

Changing the notification text

All you need to do is change the text of balloon tip and show the balloon tip:

Step1

Change the text of BalloonTip using the property BalloonTipText

Step2

Show the BalloonTipText using the method ShowBalloonTip(timeout as integer)

Monitoring BalloonTip Clicked Event

Sometimes it is necessary to call some method when user clicks the BalloonTipText. To understand it, Just add following code in Form1 Code and run the application.

Private Sub NotifyIcon1_BalloonTipClicked(ByVal sender As Object, ByVal e As EventArgs) Handles NotifyIcon1.BalloonTipClicked
        MessageBox.Show("BalloonTipClicked event is called")
    End Sub

When you click the BalloonTip, a message box is shown as response. The main idea is to create a method for handling NotifyIcon1.BalloonTipClicked event

NotifyIcon

The post Visual Basic NotifyIcon for Taskbar Notification appeared first on Bubble Blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sharjeel_Ahmad
Engineer http://bubbleblog.net/
Pakistan Pakistan
A Telecom Engineer, Visual Basic enthusiast and Android news follower. He is contributing to an online blog as content writer and administrator
You can visit him here: http://bubbleblog.net/
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 17 Mar 2014
Article Copyright 2014 by Sharjeel_Ahmad
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid