winform 窗体属性FormBorderStyle 为none时使窗体可以被移动

winform 窗体属性FormBorderStyle 为none时使窗体可以被移动

       #region 使窗体可以移动的代码

        [DllImport("user32.dll")]

        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]

        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);

        public const int WM_SYSCOMMAND = 0x0112;

        public const int SC_MOVE = 0xF010;

        public const int HTCAPTION = 0x0002;

        #endregion

 

        private void Frm_Login_MouseDown(object sender, MouseEventArgs e)

        {

            //拖动窗体

            this.Cursor = System.Windows.Forms.Cursors.Hand;//改变鼠标样式

            ReleaseCapture();

            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);

            this.Cursor = System.Windows.Forms.Cursors.Default;

        }

OK,完工了,试试看吧!

猜你喜欢

转载自blog.csdn.net/zeephom/article/details/81744821
今日推荐