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.
Paste the following code in Windows
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
NotifyIcon1.BalloonTipText = "Tool Tip Text for Windows Application"
NotifyIcon1.Text = "Windows Application"
Public Sub CreateContextMenu()
Dim contextMenu As New ContextMenu
Dim menuItem As New MenuItem("Exit")
NotifyIcon1.ContextMenu = contextMenu
AddHandler menuItem.Click, AddressOf menuItem_Click
Private Sub menuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
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 ToolTipText is shown
NotifyIcon Text is visible when mouse is hovered
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:
Change the text of
BalloonTip using the property
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 the following code in
Form1 code and run the application.
Private Sub NotifyIcon1_BalloonTipClicked(ByVal sender As Object, ByVal e As EventArgs) _
MessageBox.Show("BalloonTipClicked event is called")
When you click the
BalloonTip, a message box is shown as response. The main idea is to create a method for handling
The post Visual Basic NotifyIcon for Taskbar Notification appeared first on Bubble Blog.