C# – Move a window without titlebar/frame
by admin on Jun.06, 2010, under Programming
By setting a form’s FrameBorder property to None, the default titlebar and border of a frame gets removed.
But how can you move a window without a titlebar then?
Well, there are many solutions for this question, but it took me quite long to find one, which would also work for my current Windows 7 installation, and here’s how to do it :
1.) Insert the following code into your program:
public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [System.Runtime.InteropServices.DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [System.Runtime.InteropServices.DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); private void titelLeiste_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); }
2.) Set the MouseDown event of your form to titelLeiste_MouseDown
Now compile the project and you should be able to move your frame, despite the fact it has no titlebar.
March 21st, 2011 on 08:41
I really like yours site.. keep going
May 20th, 2013 on 15:33
Thank You.
August 29th, 2014 on 04:04
you must do some more tuts i can’t get enough:LOL: its very easy to follow and learn for a noob like me, if i were to chose a guru to learn programming language than it will be you no doubt about it thanks much