0

Possible Duplicate:
C# - Make a borderless form movable?

If I set my form's FormBorderStyle to None, I lose the drag behavior of the form, as expected.

I've added a custom bar to the top of my form and I like it to stay that way, now is it possible to keep the form in this mode and have (or write) drag behavior?

If it's possible, how should I do so. I really hope to find a Yes it's possible answer. :)

Community
  • 1
  • 1
Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94

1 Answers1

1
private const Int32 WM_NCHITTEST = 0x84;
private const Int32 HTCLIENT = 0x1;
private const Int32 HTCAPTION = 0x2;

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_NCHITTEST)
    {
        base.WndProc(ref m);

        if ((Int32)m.Result == HTCLIENT)
            m.Result = (IntPtr)HTCAPTION;

        return;
    }

    base.WndProc(ref m);
}
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • Worths to mantion that this solution treats like a TitleBar entire form surface, so making double click on any part of the form will make it maximize, so it has to be handled too. – Tigran Jan 16 '13 at 16:38
  • I suppose that these magic numbers refers to NC_HITTEST message as explained [here](http://stackoverflow.com/questions/4767831/drag-borderless-windows-form-by-mouse?rq=1) , but this is not exactly what the OP asked – Steve Jan 16 '13 at 16:38
  • @Zarathos: I just edited by adding constants to your code. – Tigran Jan 16 '13 at 16:40
  • The OP asked for a draggable form with FormBorderStyle.None. And here is how to do it. – Tommaso Belluzzo Jan 16 '13 at 16:40