将拖动行为添加到FormBorderStyle设置为None的表单中

问题描述:


可能重复:

C#-使无边界表单可移动吗?

如果我将表单的 FormBorderStyle 设置为 None ,则会丢失表单的拖动行为,这与预期的一样。

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

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