All Topics, C#, .NET >> C# Programming >> Unedited Reader C# Contributions Windows, .NET http://www.codeproject.

com/useritems/Nitifcation_from_Icon.asp (.NET 2.0) ASP.NET, Win32, VS Notification from Icon in statusbar (VS.NET2003), By Sun Rays. WebForms Notification icon will be displayed in statusbar and from Icon can open webapplication Dev Posted : 20 Nov 2007 Views : 563 Note: This is an unedited reader contribution 7 votes for this article. Popularity: 1.36. Rating: 1.61 out of 5. Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report this article.

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 using using using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms; System.Data.SqlClient; System.Diagnostics; System.Collections; System.Security; 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(http://www.codeproject.com/useritems/);/ } } }

// Here you can access any site

Now you check your application using this code.

Points of Interest

Using this code you will get a great feeling to have notification in statusbar.

Enjoy the coding..

About Sun Rays
I am working as a Software Programmer in MNC located at India. Click here to view Sun Rays's online profile.

Discussions and Feedback
0 comments have been posted for this article. Visit http://www.codeproject.com/useritems/Nitifcation_from_Icon.asp to post and view comments on this article. Updated: 20 Nov 2007 Article content copyright Sun Rays, 2007 everything else Copyright © CodeProject, 1999-2007.