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

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

你可能感兴趣的:(C#)