拖动无标题栏窗体

C#拖动无标题栏窗体,本质上还是利用windows API函数以及Windows的消息机制,具体做法如下:
//声明API函数和消息
        [DllImport("user32.dll")]
        public extern static long SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        [DllImport("user32.dll")]
        public extern static bool ReleaseCapture();

//在无标题的窗体本身或者任意可视化组件的MouseDown事件下加入如下代码:
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, 0xF017, 0);
编译,拿起鼠标拖动吧,Good Luck! 

注:最好是在Front的可视化组件的MouseDown事件中加入以上代码

posted @ 2013-09-30 08:33  美丽的矩阵  阅读(112)  评论(0)    收藏  举报