重写窗体关闭事件protected override void OnFormClosing(FormClosingEventArgs e)遇到的错误

来源:互联网 发布:图片透视软件 编辑:程序博客网 时间:2024/05/01 02:09

重写窗体点击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;