How easy it is to place an app in the system tray - .Net and C#

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxxxx>
  • To: <ProgrammingBlind@xxxxxxxxxxxxx>
  • Date: Sun, 15 May 2011 16:36:41 +0200

Had never realised just how simple/easy it actually is <smile>

While haven't really bothered with something like a context menu as of yet, I 
found an example article via codeProject, and it really just comes down to 
having a notifyIcon control on a form, and making it visible when you then hide 
the form, and the app continues running in the background, but appearing as an 
icon in the system tray, which is what was looking for this time around.

Only other thing is you do seem to need to assign an icon to the notifyIcon 
control or else it won't show in the system tray as such, but aside from that, 
and assigning it a title, etc., the following code handles it all:

private void Form1_Resize(object sender, EventArgs e)

{

if (this.WindowState == FormWindowState.Minimized)

{

this.Hide();

notifyIcon1.Visible = true;

notifyIcon1.ShowBalloonTip(500, "timeAnnouncer", "here I am...", 
ToolTipIcon.Info);

}

else if (this.WindowState == FormWindowState.Normal)

{

notifyIcon1.Visible = false;

}

}//end of form resized event

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

{

notifyIcon1.Visible = false;

this.Show();

}//end of notify icon double click



Stay well


Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

Other related posts:

  • » How easy it is to place an app in the system tray - .Net and C# - Jacob Kruger