禁用Winform关闭按钮

       禁用关闭按钮需使用窗体的WndProc处理方法,这个方法是用来截获单击关闭窗体信息的。这个要通过重写WndProc的虚方法来实现。

重写WndProc

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))//当鼠标单击“关闭”按钮时
       {
           return;//直接返回,不进行处理
       }
       base.WndProc(ref m)//传递下一条消息
}

原文地址:https://www.cnblogs.com/sinper/p/4852512.html