C#编程技巧—窗体设置为无边框后如何实现鼠标移动窗体

窗体定义操作系统自带api方法:

#region 鼠标左键移动窗体

        public const int WM_NCLBUTTONDOWN = 0xa1;

        public const int HT_CAPTION = 0x2;

        [DllImportAttribute(“user32.dll”)]

        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        [DllImportAttribute(“user32.dll”)]

        public static extern bool ReleaseCapture();

        #endregion

窗体鼠标mousedown事件实现以下代码:

if (e.Button == MouseButtons.Left)

            {

                ReleaseCapture();

                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

            }

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容