You can use APIs for this problem.
private const int HT_CAPTION = 0x2;
private const int WM_NCLBUTTONDOWN = 0x00A1;
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern bool ReleaseCapture();
[DllImport("user32", CharSet = CharSet.Auto)]
private static extern int SendMessage(
IntPtr hwnd,
int wMsg,
int wParam,
int lParam);
Use this methods from a MouseDown event, as shown here:
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
Rectangle rct = DisplayRectangle;
if (rct.Contains(e.Location))
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
}
You can also use that you've created in a mousedown event handler.