Hold up the windows message to drag your form.
There is a solution when you'd like a drag function in a non-title form or an irregular form.
Usually peopole will do as below.
1. Recorded a position when you clicked mouse’s right button.
2. Recorded the opposite position when mouse was moved.
3. Moved the form to right position when you released the left button.
Maybe there is a better solution and you can do it in an easy way.
Allow me to simply introduce the theory for you first.
A form could be dragged when we clicked the form’s title, because the OS received a message of WM_NCLBUTTONDOWN.
So you could drag the form.
Sometime the OS received WM_LBUTTONDOWN when we clicked the form without on the title.
The OS wouldn’t receive WM_NCLBUTTONDOWN if the form’s title was hidden by you.
So ~~ I think you got it.
You have to swap them when you received WM_LBUTTONDOWN.
LRESULT CMoveWindowsDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_LBUTTONDOWN: this->SendMessage(WM_NCLBUTTONDOWN,HTCAPTION); return 1; } return CDialog::WindowProc(message, wParam, lParam); }
namespace MoveWindowsCS { public partial class Form1 : Form, IMessageFilter { private const int WM_LBUTTONDOWN = 0x0201; private const int WM_NCLBUTTONDOWN = 0x00A1; private const int HTCAPTION = 2; [DllImport("user32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public Form1() { InitializeComponent(); Application.AddMessageFilter(this); } /// <summary> /// There is similar MFC /// </summary> /// <param name="m"></param> /// <returns></returns> public bool PreFilterMessage(ref Message m) { switch (m.Msg) { case WM_LBUTTONDOWN: SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); break; } return true; } } }