C# 使用WM_NCLBUTTONDOWN消息实现任意位置移动窗体

Code
 1        public const int WM_NCLBUTTONDOWN = 0xA1;
 2        public const int HT_CAPTION = 0x2;
 3
 4        [DllImportAttribute("user32.dll")]
 5        public static extern int SendMessage(IntPtr hWnd,
 6                         int Msg, int wParam, int lParam);
 7        [DllImportAttribute("user32.dll")]
 8        public static extern bool ReleaseCapture();
 9
10        private void Form1_MouseDown(object sender, MouseEventArgs e)
11        {
12            if (e.Button == MouseButtons.Left)
13            {
14                if ((e.Clicks == 1))
15                {
16                    ReleaseCapture();
17
18                    SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
19                }

20            }

21        }

你可能感兴趣的:(C# 使用WM_NCLBUTTONDOWN消息实现任意位置移动窗体)