This article will explore the details of the Notify Icons
Download
Download source code for Notify Icon
Introduction
This article will explore the Notify Icon creation. Sometime we require Icon in system which is used to manage the application. This article will explore the details related to the Notify Icon.
Images that the Application Look Like




Create Project
Please create new project with Windows application template having the language C# or VB. I have created using C#
Add Controls to the FormAdd the following controls in the Form
1. Notify Icon: This control is used to display the icon in the taskbar.
2. Context Menu Strip: This control is used to add the right click menu to the Icon in the taskbar.
3. Button: This control is used to fire event to hide the form and display the Notify Icon in the Taskbar.
Set Control's PropertiesProperties to be set for the controls
- Form
- Title
bar of the Form (Text)
- Notify
Icon
- Name
of the control (Name)
- Icon
to be display in the taskbar (Icon)
- Context
menu list (ContextMenuStrip)
- ContextMenuStrip
- List
of the Menu for Right click (Items)
- Button:
- Set
the name to identify (Name)
- Text
to display (Text)
Set the Event for the Controls
Set the events for the controls
- Button:
- Click
event: This event hides the form and makes the notify icon visible true
with balloon tip.
- ContextMenuStrip:
- ItemClicked:
This event is used to fire the event for the click of the context menu at
icon’s right click.
Event fire or execution
Button è
Click:
Step 1: Hide the form
Step 2: Make the Notify Icon visible true
Step 3: Set the Mouse hover or tool tip text (Text) property
for Notify Icon
Step 4: Display Balloon Tip
Step 5: Set the context menu property for Notify Icon that
we have created earlier.
ContextMenuStrip è ItemClicked
Step 1: Check the Item text to know which item is clicked
Step 2: Make the Effect according to it
a. If
we have selected the “Show Me”, make the form visible and hide the icon
b. If
we have selected the “Show Date Time”, display the Balloon Tip with date time
c. If
we have selected Exit, Exit from the system
C#.Net__________________________________________________________________
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace NotifyIconExample
{
public partial class NotifyIconExample : Form
{
public NotifyIconExample()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
notifyIcon1.Visible = true;
notifyIcon1.Text = "Notify Icon Example";
notifyIcon1.ShowBalloonTip(300, "Notify Icon", "Form Hidden", ToolTipIcon.Info);
notifyIcon1.ContextMenuStrip = contextMenuStrip1;
}
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Show Me")
{
this.Show();
notifyIcon1.Visible = false;
}
else if (e.ClickedItem.Text == "Show Date Time")
{
notifyIcon1.ShowBalloonTip(300, e.ClickedItem.Text, "Date Time: " + DateTime.Now.ToString(), ToolTipIcon.Info);
}
else if (e.ClickedItem.Text == "Exit")
{
if (MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
Application.Exit();
}
}
}
}
VB.Net_______________________________________________________________________
-----------------------------------------------------------------
(This code is converted from C# to vb.net)
-----------------------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Namespace NotifyIconExample
Partial Public Class NotifyIconExample
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.Hide()
notifyIcon1.Visible = True
notifyIcon1.Text = "Notify Icon Example"
notifyIcon1.ShowBalloonTip(300, "Notify Icon", "Form Hidden", ToolTipIcon.Info)
notifyIcon1.ContextMenuStrip = contextMenuStrip1
End Sub
Private Sub contextMenuStrip1_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs)
If e.ClickedItem.Text = "Show Me" Then
Me.Show()
notifyIcon1.Visible = False
ElseIf e.ClickedItem.Text = "Show Date Time" Then
notifyIcon1.ShowBalloonTip(300, e.ClickedItem.Text, "Date Time: " + DateTime.Now.ToString(), ToolTipIcon.Info)
ElseIf e.ClickedItem.Text = "Exit" Then
If MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.[Exit]()
End If
End If
End Sub
End Class
End Namespace
If you like this article, subscribe to our
RSS Feed. You can also
subscribe via email to our Interview Questions, Codes and Forums section.