C#WinForms窗体无边框拖动

来源:互联网 发布:求最大公约数c语言 编辑:程序博客网 时间:2024/05/18 01:45

  无边框的界面实现鼠标拖动

        using System.Runtime.InteropServices;                 [DllImport("user32.dll")]        static extern bool ReleaseCapture();        [DllImport("user32.dll", CharSet = CharSet.Auto)]        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);         private readonly UInt32 WM_SYSCOMMAND = 0x112;        private readonly UInt32 SC_MOVE = 0xF010;        private readonly UInt32 HTCAPTION = 2;         private void Form1_Load(object sender, EventArgs e)        {            this.MouseDown += MyMouseMove;            foreach (Control c in this.Controls)            {                c.MouseDown += MyMouseMove;            }        }         private void MyMouseMove(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                ReleaseCapture();                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);            }        }

           参考:http://bbs.csdn.net/topics/390159690


0 0
原创粉丝点击