- C#实现点击窗体关闭按钮时到系统托盘
发布时间:2011-06-29 类别:其他 来源:侠客工作室 -
- 1
- 2
- 3
- 4
- 5
C#实现点击窗体关闭按钮时到系统托盘,右键系统托盘弹出菜单点击退出退出整个程序
一、在工具箱添加notifyIcon控件,contextMenustrip控件
二、设置属性Icon ,Text ,visable(true),contextMenustrip,
三、添加窗体Closing()事件,加入代码:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生
{
e.Cancel = true;
this.ShowInTaskbar = false;
this.Hide();}
}四、添加contextMenu点击事件:
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)//实现重新显示窗体
{
if (this.Visible == false)
this.Visible = true;}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)//实现关闭整个窗体
{
Application.Exit();//通过Application类的静态方法Exit()退出应用程序
}五、实现鼠标双击任务栏图标显示程序界面:
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible == false)
this.Visible = true;
}-
中搜索:C#实现点击窗体关闭按钮时到系统托盘 中搜索:C#实现点击窗体关闭按钮时到系统托盘
中搜索:C#实现点击窗体关闭按钮时到系统托盘 中搜索:C#实现点击窗体关闭按钮时到系统托盘
中搜索:C#实现点击窗体关闭按钮时到系统托盘 中搜索:C#实现点击窗体关闭按钮时到系统托盘 - ☆☆☆技术交流群:5684178☆☆☆
- 上一篇:linux下linux下tar解压、gz解压、bz2等各种解压文件使用方法
- 下一篇:C#发送邮件使用System.Net.Mail来实现,那么在这种实现中要注意这样几个问题是什么?C#