Click here to Skip to main content
Click here to Skip to main content

Notification from Icon in statusbar

, 1 Feb 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Notification icon will be displayed in statusbar and from Icon can open webapplication

Introduction

Here is an article for displaying notification from statusbar icon. And when user will double click on that icon it will open a web application. And on right click it will display menu to Hide, Show alerts as well Exit the alerts. So we can say that here we are going to implement an application which will work together as window based as well web based application. Here the alert will be displayed from database. And when there will not any mess in database it will not display any notification. But when any mess will come in database it will pop up notification.

Here is a snipshots for the same.

Screenshot - Notify1.gif

When user right click on Icon.

Screenshot - Notify2.gif

Using the code

First we will create a window application.Name the window application as AlertMessControl. Now add one form name it as AlertMess.

Add below controls and set appropriate properties to controls:

//

// Controls of window form

//


Timer :
 this.tmrAlert.Enabled = true;
 this.tmrAlert.Interval = 2000;
 this.tmrAlert.Tick += new System.EventHandler(this.tmrAlert_Tick);

Label :
 this.lblStatus.Name = "lblStatus";

NotifyIcon :
 this.alertNot.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
 this.alertNot.BalloonTipText = "Task Arrived";
 this.alertNot.BalloonTipTitle = "New Task";
 this.alertNot.Text = "Test all task";
 this.alertNot.Visible = true;
 this.alertNot.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.alertNot_MouseDoubleClick);

Label :
 this.lblTotal.AutoSize = true;
 this.lblTotal.Name = "lblTotal";
 this.lblTotal.Text = "0";
 this.lblTotal.Visible = false;

Form Property :
 this.ControlBox = false;
 this.Name = "AlertMess";
 this.Opacity = 0.01;
 this.ShowInTaskbar = false;
 this.Text = "AlertMess";
 this.WindowState =   System.Windows.Forms.FormWindowState.Minimized;


///Now in the codebehind file AlertMess.cs write below code.




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Collections;
using System.Security;
using System.Security.Permissions;

namespace AlertMessControl
{
    public partial class AlertMess : Form
    {
        public AlertMess(string)
        {
            InitializeComponent();
        }

        private void hide_Click(object Sender, EventArgs e)
        {
            try
            {
                lblStatus.Text = "H";
                alertNot.BalloonTipText=  "";
                alertNot.Visible =false;
                alertNot.Visible =true;
                tmrAlert.Stop();
            }
            catch(Exception ex)
            {
               MessageBox.Show(ex.ToString());
            }
        }

        private void show_Click(object Sender, EventArgs e)
        {
            try
            {
                lblStatus.Text = "S";
                tmrAlert_Tick(Sender, e);
                tmrAlert.Start();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

       private void exit_Click(object Sender, EventArgs e)
        {
            try
            {
                lblStatus.Text = "E";
                Application.Exit();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void tmrAlert_Tick(object sender, EventArgs e)
        {
            GetAlerts();
        }

        private void GetAlerts()
        {
          try
            {
                if(lblStatus.Text == "H")
                {
                    alertNot.BalloonTipText=  "";
                    alertNot.Visible =false;
                    alertNot.Visible =true;
                    goto BreakProcess;
                }
                if(lblStatus.Text == "E")
                {
                    alertNot.Visible =false;
                    goto BreakProcess;
                }
                int total =0;
                SqlConnection con;
                SqlDataAdapter adp;
                con = new SqlConnection("Connection String");
                con.Open();
                adp = new SqlDataAdapter("Command to get alert messages", con);

                DataSet ds = new DataSet();
                adp.Fill(ds);
                total = ds.Tables[0].Rows.Count;
                if(Convert.ToInt32(lblTotal.Text) != total)
                {
                    alertNot.Visible = false;
                    alertNot.Visible = true;
                }

                lblTotal.Text = total.ToString();
                int i = 1;
                if(total >0)
                {
                    foreach(DataRow dr in ds.Tables[0].Rows)
                    {
                        alertNot.ShowBalloonTip(1,dr["Mess"].ToString() , ToolTipIcon.Info);
                        i++;
                    }
                    con.Close();
                }

            BreakProcess:
                // end process

                if(lblStatus.Text == "H")
                    lblStatus.Text = "H";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void AlertMess_Load(object sender, EventArgs e)
        {
            try
            {
                ContextMenu ctm = new ContextMenu();
                EventHandler ev1 = new EventHandler(hide_Click);
                ctm.MenuItems.Add("Hide Me", ev1);
                EventHandler ev2 = new EventHandler(show_Click);
                ctm.MenuItems.Add("Show Me", ev2);
                EventHandler ev3 = new EventHandler(exit_Click);
                ctm.MenuItems.Add("Exit", ev3);
                alertNot.ContextMenu = ctm;
                GetAlerts();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void alertNot_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("Task Searching......");
            Process prs = Process.Start(<a href=");/">http://www.codeproject.com);</a>           // Here you can access any site

        }
    }
}








<p>Now you check your application using this code. </p>

<h2>Points of Interest</h2>

<p>Using this code you will get a great feeling to have notification in statusbar.</p>

<p>Enjoy the coding.. </p>

License

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

Share

About the Author

Sun Rays
Team Leader
India India
Working as a Team Lead in MNC located at India.
In IT world, I have worked with Microsoft Technologies and always ready for R&D.
Worked with Website Development and Windows based applications as well.
 

New errors are really good and being happy to resolve those.....

Comments and Discussions

 
GeneralMy vote of 1 Pinmembervcarnei7-Jul-09 9:59 
GeneralRe: My vote of 1 PinmemberFernandaUY12-Jan-12 15:55 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 1 Feb 2008
Article Copyright 2007 by Sun Rays
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid