您的位置:首页 > 其它

使用NotifyIcon将窗口最小化到任务栏区域

2007-04-12 17:49 405 查看
采用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菜单。

//退出
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: