Add drag behavior to a form with FormBorderStyle set to None [duplicate]

混江龙づ霸主 提交于 2019-12-11 18:45:15

问题


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. :)


回答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);
}


来源:https://stackoverflow.com/questions/14363162/add-drag-behavior-to-a-form-with-formborderstyle-set-to-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!