我希望标题栏上的“x”按钮关闭整个应用程序,而不是当前的表单。我该怎么做?
答案 0 :(得分:4)
在表单上为FormClosed
事件连接一个事件处理程序,然后调用Application.Exit()
。例如:
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
答案 1 :(得分:2)
@rsbarro是对的,但我希望更具体。
private void Form_FormClosed(object sender, FormClosingEventArgs e)
{
// if close button clicked, not the computer is being shutdown or anyother reason
if (e.CloseReason == CloseReason.UserClosing)
{
Application.Exit();
}
}