Advertisement
JulianoLoren

Move window/form without Titlebar in C#

Mar 15th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System.Runtime.InteropServices;
  2.  
  3. public const int WM_NCLBUTTONDOWN = 0xA1;
  4. public const int HT_CAPTION = 0x2;
  5.  
  6. [DllImportAttribute("user32.dll")]
  7. public static extern int SendMessage(IntPtr hWnd,
  8. int Msg, int wParam, int lParam);
  9. [DllImportAttribute("user32.dll")]
  10. public static extern bool ReleaseCapture();
  11.  
  12. //Then put the following two lines of code in the form's MouseDown event like this:
  13.  
  14. Collapse | Copy Code
  15. private void Form1_MouseDown(object sender,
  16. System.Windows.Forms.MouseEventArgs e)
  17. {
  18. if (e.Button == MouseButtons.Left)
  19. {
  20. ReleaseCapture();
  21. SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement