C# 面板作为 MDI 容器

标签 c# forms panel mdi

在 C# 中,我想创建一个具有 MDI 容器属性的面板,即。 isMdiContainer = true。

我试过这样的东西

form.MDIParent = this.panel1;

但这行不通。有什么建议吗?

最佳答案

可以创建一个 MDI 面板并在该面板中显示表单,类似下面的代码就可以完成这项工作

Mdi-Panel 定义:

public class MdiClientPanel : Panel
{
    private Form mdiForm;
    private MdiClient ctlClient = new MdiClient();

    public MdiClientPanel()
    {
        base.Controls.Add(this.ctlClient);
    }

    public Form MdiForm
    {
        get
        {
            if (this.mdiForm == null)
            {
                this.mdiForm = new Form();
                /// set the hidden ctlClient field which is used to determine if the form is an MDI form
                System.Reflection.FieldInfo field = typeof(Form).GetField("ctlClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                field.SetValue(this.mdiForm, this.ctlClient);
            }
            return this.mdiForm;
        }
    }
}

用法:

/// mdiChildForm is the form that should be showed in the panel
/// mdiClientPanel is an instance of the MdiClientPanel
myMdiChildForm.MdiParent = mdiClientPanel1.MdiForm;

关于C# 面板作为 MDI 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/941306/

相关文章:

c# - 带有 directshow 视频渲染器的移动面板

java - 为什么更换内面板时会出现闪烁?

c# - 从 DataTable 中删除列名中的空格

c# - CamelCase 转换为友好名称,即枚举常量;问题?

c# - 当父子在同一个表中时如何从数据库加载数据到TreeView

javascript - vue 表单 e.target.name.value 未定义

python - 使用 Python mechanize 通过登录屏幕

php - JQuery 使用 PHP GET 从文本框重新加载 DIV 层

c# - Entity Framework - 如何不更新相关对象

css - 最常用的 Bootstrap CDN 链接/链接?