WinForm no window frame to change the size and movement of the form

 #region without changing the size of moving window frame 
      
        [the DllImport ( " User32.dll " )]
         public  static  extern  BOOL the ReleaseCapture (); 
        [the DllImport ( " User32.dll " )]
         public  static  extern  BOOL the SendMessage (IntPtr HWND, int WMsg, int the wParam, int the lParam); 

        public  const  int the WM_SYSCOMMAND = 0x0112 ;
         public  const  int SC_MOVE = 0xF010 ;
         public const int HTCAPTION = 0x0002;
        const int HTLEFT = 10;
        const int HTRIGHT = 11;
        const int HTTOP = 12;
        const int HTTOPLEFT = 13;
        const int HTTOPRIGHT = 14;
        const int HTBOTTOM = 15;
        const int HTBOTTOMLEFT = 0x10;
        const int HTBOTTOMRIGHT = 17;

        public bool ManualResize
        {
            get
            {
                return this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.None
                    && this.WindowState == FormWindowState.Normal;
            }
        }

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x0084:
                    base.WndProc(ref m);
                    if (ManualResize)
                    {
                        Point vPoint = new Point((int)m.LParam & 0xFFFF,
                            (int)m.LParam >> 16 & 0xFFFF);
                        vPoint = PointToClient(vPoint);
                        if (vPoint.X <= 5)
                            if (vPoint.Y <= 5)
                                m.Result = (IntPtr)HTTOPLEFT;
                            else if (vPoint.Y >= ClientSize.Height - 5)
                                m.Result = (IntPtr)HTBOTTOMLEFT;
                            else m.Result = (IntPtr)HTLEFT;
                        else if (vPoint.X >= ClientSize.Width - 5)
                            if (vPoint.Y <= 5)
                                m.Result = (IntPtr)HTTOPRIGHT;
                            else if (vPoint.Y >= ClientSize.Height - 5)
                                m.Result = (IntPtr)HTBOTTOMRIGHT;
                            else m.Result = (IntPtr)HTRIGHT;
                        else if (vPoint.Y <= 5)
                            m.Result = (IntPtr)HTTOP;
                        else if (vPoint.Y >= ClientSize.Height - 5)
                            m.Result = (IntPtr)HTBOTTOM;
                    }
                    break;
                case 0x0201:    //鼠标左键按下的消息
                    if (ManualResize)
                    {
                        m.Msg = 0x00A1 ;     // change the message by pressing the mouse non-client area 
                        m.LParam = IntPtr.Zero;     // Default 
                        m.WParam = new new IntPtr ( 2 );     // mouse on the title bar 
                    }
                     Base .WndProc ( REF m);
                     BREAK ;
                 default :
                     the try 
                    { 
                        Base .WndProc ( REF m); 
                    } 
                    the catch (Exception) {}
                     BREAK ;
            } 
        } 
        #Endregion

Guess you like

Origin www.cnblogs.com/yc1224/p/12071963.html