0

我正在开发一个继承自 Form 类的类库,然后在 Gui 应用程序中显示此表单。现在我需要将类库更改为UserControl.

如何在另一个项目的表单中显示它? 提前感谢您的建议。

IFaceForm 是 InterfaceLibrary 内部的用户控件。

using InterfaceLibrary;

namespace MxlInterface
{  
    public partial class IFaceConn : Form
    { 
        iFaceForm Interface = new iFaceForm();

        //size of the parent form is 881,514
        //use these variables to change the position of the "Interface Form"
        int xlocation = 0;
        int ylocation = 0;

        public IFaceConn()
        {
            InitializeComponent();

            //Interface.StartPosition = FormStartPosition.Manual;
            Interface.Location = new Point(xlocation, ylocation);
            //Interface.MdiParent = this;

            Interface.Show();
        }
    }
}
4

1 回答 1

4

您可以通过执行以下操作直接将其添加到表单中:

MyUserControl myControl = new MyUserControl();
Controls.Add(myControl);

Panel在表单上放置一个可以作为用户控件占位符的a 也很有用,然后将用户控件添加到该面板:

MyUserControl myControl = new MyUserControl();
myControlWrapperPannel.Controls.Add(myControl;
于 2013-02-13T19:04:27.217 回答