winForm 实现鼠标拖动标题栏不移动窗口 和 拖动用户区移动窗口

实现鼠标拖动标题栏不移动窗口

protected   override   void   WndProc(ref   System.Windows.Forms.Message   m) 
        
                base.WndProc(ref   m);//基类执行 
                if(m.Msg   ==   132)//鼠标的移动消息(包括非窗口的移动) 
                
                        //基类执行后m有了返回值,鼠标在窗口的每个地方的返回值都不同 
                        if((IntPtr)2   ==   m.Result)//如果返回值是2,则说明鼠标是在标题拦 
                        
                                //将返回值改为1(窗口的客户区),这样系统就以为是 
                                //在客户区拖动的鼠标,窗体就不会移动 
                                m.Result   =   (IntPtr)1; 
                        
                
        

拖动用户区移动窗口:

        protected override void WndProc(ref System.Windows.Forms.Message  m)
        {
            base.WndProc(ref m);
            if (m.Msg == 132)
            {
                if ((IntPtr)1 == m.Result)
                {
                    m.Result = (IntPtr)2;
                }
            }
        }

原文地址:https://www.cnblogs.com/susuzhao/p/3423520.html