1 using System.Runtime.InteropServices;
2
3 public partial class MainForm : Form
4 {
5
6 [DllImport("user32.dll")]
7 public static extern bool ReleaseCapture();
8 [DllImport("user32.dll")]
9 public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
10 public const int WM_SYSCOMMAND = 0x0112;
11 public const int SC_MOVE = 0xF010;
12 public const int HTCAPTION = 0x0002;
13
14 /// <summary>
15 /// 控件的MouseDown事件
16 /// </summary>
17 /// <param name="sender"></param>
18 /// <param name="e"></param>
19 private void ShapedForm_MouseDown(object sender, MouseEventArgs e)
20 {
21 //拖动窗体
22 ReleaseCapture();
23 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
24 }
25
26 }