1

我在尝试从这个Dock Container中删除表单时遇到了麻烦,一旦我使用了dockContainer.Add(form)dockContainer.Remove(dockableFormInfo)然后当我使用 使其显示自己时form.Show(),它根本不会显示。

通过属性查看它显示表单实际上是visible = true,但即使使用 Form 的可停靠控件已从容器中删除,我的想法是它仍然使用 Form 资源,因此我无法使其出现在控件之外.

如何使表格显示?

4

1 回答 1

0

问题解决了,首先感谢 Hans Passant 的 TopLevel 提示。

从停靠容器中移除后,只需将TopLevel 设置为 true

这是测试代码:

using System;
using System.Drawing;
using System.Windows.Forms;
using Crom.Controls.Docking;

namespace DockingTester
{
    public partial class Form1 : Form
    {
        private Form dummyForm;
        private readonly Guid dummyFormGuid = Guid.NewGuid();


        public Form1()
        {
            InitializeComponent();
            CreateDummyForm();
            this.dummyForm.Show();
        }

        private void CreateDummyForm()
        {
            dummyForm = new Form();
            this.dummyForm.Text = "Dummy docking test form";
        }

        private static void DockUndockForm(DockContainer dockContainer, Form form, Guid guid)
        {
            DockableFormInfo formInfo = dockContainer.GetFormInfo(guid);

            //Add
            if (formInfo == null)
            {
                formInfo = dockContainer.Add(form, zAllowedDock.All, guid);
                dockContainer.DockForm(formInfo, DockStyle.Left, zDockMode.Inner);
            }
            //Remove
            else
            {
                Form dummy =  formInfo.DockableForm;
                dockContainer.Undock(formInfo, new Rectangle(Point.Empty, new Size(100, 300)));
                dockContainer.Remove(formInfo);

                dummy.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                dummy.TopLevel = true;
            }
        }

        private void dockUndockButton_Click(object sender, EventArgs e)
        {
            if (this.dummyForm.IsDisposed)
                CreateDummyForm();
            DockUndockForm(this.dockContainer1, this.dummyForm, this.dummyFormGuid);
        }

    }
}
于 2013-01-25T12:57:21.507 回答