您的位置:首页 > 其它

最小化到托盘,右键退出

2016-06-12 13:19 204 查看

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;
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: