C# 鼠标任意拖动无边框窗体(调用API函数)。

引入命名空间using System.Runtime.InteropServices;

声明API函数

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();

        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);

 

在窗体的鼠标单击事件中引用

        private void Frm_Login_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(base.Handle, 0x112, 0xf012,0);
        }

这样便可支持鼠标拖动无边框窗体

 

posted @ 2017-02-15 10:12  xmy_007  阅读(622)  评论(0编辑  收藏  举报