Yesterday my colleague Alexander Jung read the articel I posted yesterday about dragging WinForms. And he showed me a solution for dragging windows that is much smarter than the solution I posted.
So I don’t want to keep back that solution.
Instead of implementing a drag routine for the WinForm, we can fool the system so that Windows thinks that the hole WinForm is a Caption (TitleBar). This can be done by intercepting the Windows Message WM_NCHITTEST and returning HTCAPTION if the user tries to drag the window.
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
/// Handling the window messages
protected override void WndProc(ref Message message)
if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
message.Result = (IntPtr)HTCAPTION;
The example solution can be downloaded using the following link.
Enhanced: Drag and move WinForms (without having a titlebar)