Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7000 |  Welcome, Guest!   Register  Login
Home > Articles > C# > Notify Icon

Notify Icon

1 vote(s)
Rating: 5 out of 5
Article posted by Neeks on 7/27/2010 | Views: 4492 | Category: C# | Level: Beginner red flag


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 Form
Add 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 Properties

Properties to be set for the controls

  1. Form
    1. Title bar of the Form (Text)
  2. Notify Icon
    1. Name of the control (Name)
    2. Icon to be display in the taskbar (Icon)
    3. Context menu list (ContextMenuStrip)
  3. ContextMenuStrip
    1. List of the Menu for Right click (Items)
  4. Button:
    1. Set the name to identify (Name)
    2. Text to display (Text)

Set the Event for the Controls

Set the events for the controls

  1. Button:
    1. Click event: This event hides the form and makes the notify icon visible true with balloon tip.
  2. ContextMenuStrip:
    1. 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


Code:

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.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:http://www.neeks4ever.blogspot.com/
Member since:Tuesday, November 25, 2008
Level:Bronze
Status: [Member]
Biography:Keep posting and Enjoy coding...
>> Write Response - Respond to this post and get points
Related Posts

Detect or Start a processing of a file only after it has copied to you system.

WeakReference comes very handy when working with Large objects. In this application, I have demonstrated how you could easily use this class to improve the performance of your application.

We will see The C# threading model.

This article describes the difference between value types and reference types and also shows how it is stored into the heap and stack.

Text file is the most convenient way to store any kind of data temporarily and very frequently used these days in any kinds of applications. This article shows different ways of reading and writing text files data in .NET.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 8:18:00 AM