在WinForm中显示UserControl
本文关键字:UserControl 显示 WinForm | 更新日期: 2023-09-27 17:58:56
我正在开发一个类库,该类库从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();
}
}
}
您可以通过执行以下操作将其直接添加到表单中:
MyUserControl myControl = new MyUserControl();
Controls.Add(myControl);
在表单上放置一个Panel
,它可以作为用户控件的占位符,然后将用户控件添加到该面板中,这通常也很有用:
MyUserControl myControl = new MyUserControl();
myControlWrapperPannel.Controls.Add(myControl;