Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Moveable non-standard shape form

0.00/5 (No votes)
19 Dec 2010 1  
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).

C#
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);
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here