1
Answer

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

Ask a question
thiago costa

thiago costa

13y
1.8k
1
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)