如何拦截窗体关闭事件,使得关闭对话框能弹出,并让用户再选择后再关闭?
我试了在FormClosing 和 FormClosed事件中都不行啊, 该怎么办啊
------解决方案--------------------/// <summary>
/// 窗口关闭前的事件
/// </summary>
/// <param name= "sender "> </param>
/// <param name= "e "> </param>
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (ExitApplication &&
MessageBox.Show(MainFormResources.IsCloseForm, MainFormResources.ConfirmDialogs, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
e.Cancel = true;
}
/// <summary>
/// 窗口关闭后的事件
/// </summary>
/// <param name= "sender "> </param>
/// <param name= "e "> </param>
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (ExitApplication)
this.Exit();
}