开发者

Add Form to a UserControl - is this possible?

Normally, controls are being added to forms. But I need to do an opposite thin开发者_JAVA百科g - 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.


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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜