C# 窗体无边框 实现窗体移动(可在指定位置)

来源:互联网 发布:淘宝买的药是真的吗 编辑:程序博客网 时间:2024/05/21 10:26

需加上using指令集:

using System.Runtime.InteropServices;

 

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();//该函数从当前线程中的窗口释放鼠标捕获,并恢复通常的鼠标输入处理。捕获鼠标的窗口接收所有的鼠标输入(无论光标的位置在哪里),除非点击鼠标键时,光标热点在另一个线程的窗口中。
        [DllImport("user32.dll")]


        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;

 

      然后指定在窗体或任一控件的mousedown事件下完成:(Form1_mousedown或panel1.mousedown 等等)

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

 

            试试吧!
原创粉丝点击