父窗体到面板 [英] Parent a form to a panel

查看:419
本文介绍了父窗体到面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一面树视图的形式。根据选择什么节点,我希望在右侧显示不同的内容。为了保持code和控制管理,我的计划是孤立内容纳入单独的形式,并显示在面板内部的形式。

I have a form with a treeview on one side. Depending on what node is selected, I want to display different content on the right. To keep code and controls manageable, my plan was to isolate content into seperate forms, and display the form inside a panel.

在我的TreeView AfterSelect事件,我试图实例的形式,并设置它的父面板,但我得到一个异常顶级控件不能被添加到一个控制。

In my TreeView AfterSelect event, I tried instantiating the form, and setting it's Parent to a panel but I get an exception "Top-level control cannot be added to a control.":

Form frmShow = new MyForm();
frmShow.Parent = this.pnlHost;

这是不是一个MDI的配置,但我想MdiParent属性设置形式父窗体,然后在窗体的父属性设置为面板,但我得到的指定是的MdiParent这种形式异常表不是MdiContainer参数名称:值:

This is not an MDI configuration, but I tried setting the forms MdiParent property to the parent form, and then setting the form's Parent property to the panel but I get an exception "Form that was specified to be the MdiParent for this form is not an MdiContainer. Parameter name: value":

Form frmShow = new MyForm();
frmShow.MdiParent = this;
frmShow.Parent = this.pnlConfigure;

我不能设置窗体为MDI容器,因为它不是一个顶级的形式,但它实际上是停靠父表单中(使用WeifenLuo对接库)的形式。

I can't set the form as an MDI Container because it is not a top level form, it is actually a form that is docked inside a parent form (using the WeifenLuo docking library).

有没有一些方法,以父面板在非MDI框架?

Is there some way to parent a form in a panel in a non MDI framework?

推荐答案

您会更好创造每一个面板作为用户控件。这些都是一样的形式,但没有窗口元素

You would be better off creating every panel as a UserControl. These are just like forms, but without the window elements.

这篇关于父窗体到面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆