重写窗体点击X时的关闭事件
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (e.CloseReason == CloseReason.WindowsShutDown) return;
switch (MessageBox.Show(this, "Do you want to close?", "Closing", MessageBoxButtons.YesNo))
{
case DialogResult.No:
e.Cancel = true;
break;
default:
break;
}
}
出现错误:Error 1 The type or namespace name 'FormClosingEventArgs' could not be found (are you missing a using directive or an assembly reference?)
解决方法:加入using System.Windows.Forms;