添加表格到用户控件 - 这可能吗? [英] Add Form to a UserControl - is this possible?
本文介绍了添加表格到用户控件 - 这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一般情况下,控制被添加到形式。但我需要做一个相反的事 - 添加一个窗体实例容器的用户控件
Normally, controls are being added to forms. But I need to do an opposite thing - add a Form instance to container user control.
这背后的原因是,我需要嵌入一个第三方应用到我自己。形式转换为用户控制是不可行的,由于复杂性。
The reason behind this is that I need to embed a third-party application into my own. Converting the form to a user control is not feasible due to complexity.
推荐答案
这是可以通过表单的顶层属性设置为false。其中把它变成一个子窗口,从用户控件几乎没有区别。下面是与所需的code示例用户控件:
This is possible by setting the form's TopLevel property to false. Which turns it into a child window, almost indistinguishable from a UserControl. Here's a sample user control with the required code:
public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();
}
public void EmbedForm(Form frm) {
frm.TopLevel = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Visible = true;
frm.Dock = DockStyle.Fill; // optional
this.Controls.Add(frm);
}
}
这篇关于添加表格到用户控件 - 这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文