让子窗体在 MdiChild 和 Normal 之间切换?

Having a child form switch between MdiChild and Normal?

我目前正在尝试重新创建 visual studio 的对接 Panel/forms。我想将同一个系统应用于不同的项目以处理不同的 window 视图,但首先我想重新创建它。

到目前为止,我一直在 MainForm 和 null 之间切换 MDiParent 属性,但无法重新创建 Visual Studio 中看到的平滑过渡。它总是很糟糕,有一半时间我发现我将开关绑定到的 MouseUP 事件很少起作用(我目前正在使用 Location change 事件)。

为了移动表单,我一直在使用我发现的这个方便的代码块;

 #region Form Movement

    public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;

    [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    private void MoveForm()
    {
        ReleaseCapture();
        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
    }

    #endregion

为了处理 Dock/UnDock,我正在使用此代码;

    private void DockToMain()
    {
        Point f = Form1.Main.PointToClient(this.Location);
        Point newP = new Point(f.X - 25, f.Y - 51);
        try { this.MdiParent = Form1.Main; } catch { }
        this.Location = newP;
    }

    private void UnDockFromMain()
    {
        Point f = Form1.Main.PointToScreen(this.Location);
        Point newP = new Point(f.X + 25, f.Y + 51);
        try { this.MdiParent = null; } catch { }
        this.Location = newP;
    }

有没有办法在 Winforms 中重新创建 Dock Panel/Form?我在这里是否走在正确的轨道上,或者有没有更好的方法我没有看到?

只是为了回答这个问题,Will 是完全正确的。我不知何故让它有点工作,但它太小故障了,没有任何用处。只需切换到 WPF(从 WinForms 跳转并不难)并使用 xceedsoftware 的“ Extended WPF Toolkit

中的 Avalon 停靠控件