65.9K
CodeProject is changing. Read more.
Home

Moveable non-standard shape form

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.64/5 (10 votes)

Dec 9, 2010

CPOL
viewsIcon

13508

Trick for dragging the form while clicking on the client area

This is a trick for dragging the form while clicking on the client area (assuming that the header of the form is removed).
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 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, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
         ReleaseCapture();
         SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }
}
Moveable non-standard shape form - CodeProject