25 November 2008

C# System Tray Minimize To Tray With NotifyIcon

Minimize application form to system tray is done
with the NotifyIcon control in Visual Studio.

NotifyIcon is in the System.Windows.Forms namespace.
Drag and drop a NotifyIcon control to your form.
To send your application form into the system tray,
we simple handle the form re-size event.
private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
mynotifyicon.Visible = true;
mynotifyicon.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
mynotifyicon.Visible = false;
}
}
We can also set BallonTipIcon, BallonTipText, BallonTipTitle and Icon ,
for our NotifyIcon control.
 mynotifyicon.BallonTipText = "My application still working...";
mynotifyicon.BallonTipTitle = "My Sample Application";
mynotifyicon.BallonTipIcon = ToolTipIcon.Info;

12 comments:

ZOverLord said...

Please see this as well Click Here for another example

Autostorage said...

Thank you ^^

Norbert Willhelm said...

Thank you.

Anonymous said...

Thank you

Anonymous said...

thankyou

Anonymous said...

Thank You!!!

Anonymous said...

Thank you, really it's helpful

Anonymous said...

Thank you very much,
but I think there is a little mistake in the second code block:
You wrote balloon just with one "o" ;).

Dominik Ras said...

Keep in mind you may need

//
// frmMain
//
this.Resize += new System.EventHandler(this.frmMain_Resize);




in your Designer.cs

Anonymous said...

Dominik Ras
THANK YOU for advise
i need that to minimize

Anonymous said...

when the applicarion are running, in windows xp i can´t shut down the pc, i need close the aplication and after shut down the pc. Anity idea??????

cosine said...

For a form that minimizes to the tray to be brought back up by a click of the NotifyIcon, I use

private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
notifyIcon.Visible = true;
this.Hide();
}
}

private void notifyIconGT_Click(object sender, EventArgs e)
{
notifyIconGT.Visible = false;
this.Show();
this.WindowState = FormWindowState.Normal;
}


Make sure the NotifyIcon is marked as not visible from within the form designer.