using System.Runtime.InteropServices;
......public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2; [DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture(); private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
......public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2; [DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture(); private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
private Point mypoint; private void Form1_Load(object sender, System.EventArgs e)
{
this.MouseDown+=new System.Windows.Forms.MouseEventHandler(this.Form_MouseDown );
this.MouseMove +=new System.Windows.Forms.MouseEventHandler(this.Form_MouseMove );
} private void Form_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
this.mypoint=new Point(-e.X,-e.Y) ;
}
private void Form_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button==MouseButtons.Left)
{
this.SetDesktopLocation(this.Left+e.X +this.mypoint .X ,this.Top +e.Y +this.mypoint .Y );
}