Click here to Skip to main content
15,886,724 members
Articles / Desktop Programming / Windows Forms
Tip/Trick

Moveable non-standard shape form

Rate me:
Please Sign up or sign in to vote.
4.64/5 (10 votes)
19 Dec 2010CPOL 13K   9   2
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
is a poor software developer and thinker. Presently working on a theory of "complementary perception". It's a work in progress.

Comments and Discussions

 
GeneralIf you do that, how do you allow clicking on the form withou... Pin
Dr.Walt Fair, PE10-Dec-10 9:51
professionalDr.Walt Fair, PE10-Dec-10 9:51 
GeneralMhm. Pin
Vercas13-Dec-10 8:48
Vercas13-Dec-10 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.