Dragon in the sky

whatever happened , go ahead! Happy life of big pig and its dog.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#窗口关闭时最小化到托盘

Posted on 2009-12-23 16:29  龙泰  阅读(3427)  评论(0编辑  收藏  举报
C#窗口关闭时最小化到托盘

//初始化退出标识
private DialogResult result = DialogResult.No;
//Yes关闭窗口,No最小化窗口
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (result == DialogResult.Yes)
{
e.Cancel = false;
Application.Exit();
}
else
{
e.Cancel = true;
this.Hide();
this.Visible = false;
}
}
//关闭按钮,给result赋值
private void btnExit_Click(object sender, EventArgs e)
{
result=MessageBox.Show("确认退出窗口吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
Application.Exit();
}

From : http://www.tansea.cn/article.asp?id=109