C# 重写 winform 关闭按钮

时间:2023-02-11 23:44:26

  //拦截Windows消息
  protected override void WndProc(ref   Message m)
        {
            const int WM_SYSCOMMAND = 0x0112;
            const int SC_CLOSE = 0xF060;
            if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
            {
                 //捕捉关闭窗体消息      
                Application.ExitThread();

       return;
            }
            base.WndProc(ref   m);
        }