vb.net: W7 Snap feature doesnt work with formborderstyle = none

232 views Asked by At

I made a custom form with a panel to represent the top bar with custom controlbox and set FormBorderStyle to None.

Now I notice that the W7 Snap feature doesn't work on my form. I have no idea how to fix this, and Google isn't really helping this time.

1

There are 1 answers

1
SLaks On

You should be able to fix this by making some portion of your form behave like a title bar.

To do that, handle the WM_NCHITTEST message and return HTCAPTION.

protected override void WndProc(ref Message m) {
    base.WndProc(ref m);
    switch (m.Msg) {
        case 0x84: //WM_NCHITTEST
            var point = new Point(m.LParam.ToInt32());
            if (point is somewhere)
                m.Result = new IntPtr((int)HitTest.Caption);

            break;
    }
}

enum HitTest {
    Caption = 2,
    Transparent = -1,
    Nowhere = 0,
    Client = 1,
    Left = 10,
    Right = 11,
    Top = 12,
    TopLeft = 13,
    TopRight = 14,
    Bottom = 15,
    BottomLeft = 16,
    BottomRight = 17,
    Border = 18
}