thiago costa

thiago costa

  • NA
  • 319
  • 0

How to make you able to "Click Anywhere On Form To Move It" in c# ?

Sep 28 2011 9:30 PM
Hey, My program will look better with out the form boarder, how do I make it so I can move it on the screen by clicking on ANYWHERE on the form, and dragging it ? thanks



************** EDIT**************

I got it !!! This is how I did it:




using System.Runtime.InteropServices;

const int HT_CAPTION = 0x2;
const int WM_NCLBUTTONDOWN = 0xA1;

[
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);
  }
}

Answers (1)