采用NotifyIcon控件、记得要将窗体showintaskbar=true/false,它主要用来控制是否在任务栏显示。记得要给icon设置图片。
代码如下:
1
//
窗体最小化事件
2 private void pbMinisize_Click( object sender, System.EventArgs e)
3 {
4 // Set the WindowState to normal if the form is minimized.
5 WindowState = FormWindowState.Minimized;
6 // 指示是否在Windows任务栏中显示窗体
7 this .ShowInTaskbar = false ;
8 notifyIcon1.Visible = true ;
9 }
10 #endregion
11
12 // 任务栏区域的双击事件
13 private void notifyIcon1_DoubleClick( object Sender, EventArgs e)
14 {
15 // Show the form when the user double clicks on the notify icon.
16 if ( this .WindowState == FormWindowState.Minimized)
17 this .WindowState = FormWindowState.Normal;
18 this .Activate();
19 this .ShowInTaskbar = true ;
20 this .notifyIcon1.Visible = false ;
21 }
用menuItem来设置任务栏区域的click菜单。
2 private void pbMinisize_Click( object sender, System.EventArgs e)
3 {
4 // Set the WindowState to normal if the form is minimized.
5 WindowState = FormWindowState.Minimized;
6 // 指示是否在Windows任务栏中显示窗体
7 this .ShowInTaskbar = false ;
8 notifyIcon1.Visible = true ;
9 }
10 #endregion
11
12 // 任务栏区域的双击事件
13 private void notifyIcon1_DoubleClick( object Sender, EventArgs e)
14 {
15 // Show the form when the user double clicks on the notify icon.
16 if ( this .WindowState == FormWindowState.Minimized)
17 this .WindowState = FormWindowState.Normal;
18 this .Activate();
19 this .ShowInTaskbar = true ;
20 this .notifyIcon1.Visible = false ;
21 }
//
退出
private void menuItem1_Click( object Sender, EventArgs e)
{
this .Close();
}
// 打开
private void menuItem2_Click( object sender, System.EventArgs e)
{
this .WindowState = FormWindowState.Normal;
this .Activate();
this .ShowInTaskbar = true ;
this .notifyIcon1.Visible = false ;
}
private void menuItem1_Click( object Sender, EventArgs e)
{
this .Close();
}
// 打开
private void menuItem2_Click( object sender, System.EventArgs e)
{
this .WindowState = FormWindowState.Normal;
this .Activate();
this .ShowInTaskbar = true ;
this .notifyIcon1.Visible = false ;
}