Just copy and paste the FormMove.cs file's content from this gist into your form's Form1.cs file in your solution that you wanna make movable.
Read More:
Just copy and paste the FormMove.cs file's content from this gist into your form's Form1.cs file in your solution that you wanna make movable.
Read More:
| namespace WindowsFormApplication1 { | |
| public partial class Form1: Form { | |
| public Form1() { | |
| InitializeComponent(); | |
| } | |
| public const int WM_NCLBUTTONDOWN = 0xA1; | |
| public const int HT_CAPTION = 0x2; | |
| [System.Runtime.InteropServices.DllImport("user32.dll")] | |
| public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); | |
| [System.Runtime.InteropServices.DllImport("user32.dll")] | |
| public static extern bool ReleaseCapture(); | |
| private void FormMove(object sender, MouseEventArgs e) { | |
| if (e.Button == MouseButtons.Left) { | |
| this.Cursor = Cursors.SizeAll; | |
| ReleaseCapture(); | |
| SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); | |
| this.Cursor = Cursors.Arrow; | |
| } | |
| } | |
| } |