//利用Windows 的 API 函数:SendMessage 和 ReleaseCapture
const uint WM_SYSCOMMAND = 0x0112;
const uint SC_MOVE = 0xF010;
const uint HTCAPTION = 0x0002;
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, uint wParam, uint lParam);
[DllImport("user32.dll")]
private static extern int ReleaseCapture();
//创建控件 mouseDown 事件
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}