我不希望在右键单击任务栏按钮时弹出的菜单中单击“关闭窗口”选项时,窗体退出。相反,我希望应用程序最小化到系统托盘。如何更改“关闭窗口”的行为?
发布于 2012-07-19 04:29:36
添加OnFormClosing的重写并查看事件参数的CloseReason。可能是这样的:
protected override OnFormClosing(FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
}
else
{
this.Close();
}
}这样,用户不能关闭您的窗体(只隐藏它),但Windows仍然可以出于其他原因(例如关机)。
https://stackoverflow.com/questions/11549696
复制相似问题