标签:
1.添加notifyIcon1,并添加Icon图标(.ico文件)
2.添加contextMenuStrip1
3.contextMenuStrip1.Items属性添加选项
4.界面上双击选项编写事件
5.选项退出
private void toolStripMenuItem1_Click(object sender, EventArgs e) { Application.Exit(); }
6.主窗预定Resize事件
if (this.WindowState == FormWindowState.Minimized) //最小化到系统托盘 { this.notifyIcon1.Visible = true; //显示托盘图标 this.Hide(); //隐藏窗口 }
7.主窗预定关窗事件
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { //注意判断关闭事件Reason来源于窗体按钮,否则用菜单退出时无法退出! if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; //取消"关闭窗口"事件 this.WindowState = FormWindowState.Minimized; //使关闭时窗口向右下角缩小的效果 this.notifyIcon1.Visible = true; this.Hide(); return; } }
标签:
原文地址:http://www.cnblogs.com/aoyeyuyan/p/5277633.html