step1. Create a solution with C# winfrom project. now,we hava a new Form named "form1"
step2. Drag-Drop an NotifyIcon control named "notifyIcon1"
step3. Drag-Drop a ContextMenu control named "contextMenu1"
step4. Set notifyIcon1's properties:
A.Icon: Select an icon file
B.Text: Change it as your wish
C.ContextMenu:Choose "contextMenu1" in the dropdownlist
D.Visable:Let it be "false"
step5. Add contextMenu1's child Items:
A.Add an new item named "menuItem1" and property "Text" is "show"
B.Add the second item named "menuItem3" and property "Text" is "close"
step6.Add methods for controlling TrayIcon:
{
notifyIcon1.Dispose();
}
private void TrayIconShow()
{
notifyIcon1.Visible=true;
this.ShowInTaskbar=false;
this.Hide();
}
private void TrayIconHide()
{
notifyIcon1.Visible=false;
this.ShowInTaskbar=true;
this.Show();
this.WindowState=FormWindowState.Normal;
}
step7.Add form1's Resize Events ,with codes like this:
{
if(this.WindowState==FormWindowState.Minimized)
TrayIconShow();
}
step8. Add MenuItems' Events
{
if(this.WindowState==FormWindowState.Minimized)
TrayIconHide();
}
private void menuItem3_Click( object sender, System.EventArgs e)
{
Application.Exit();
}
step9.Enjoy it after hitting F5
Example Source !