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)
{
base.WndProc(ref 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)
July 8, 2011 at 4:02 am
How to do it, if we want certain control in the form to act as title bar.
September 10, 2012 at 6:44 pm
With controls support.
http://www.codeproject.com/Articles/11114/Move-window-form-without-Titlebar-in-C