C# 在WinForm中显示UserControl
我正在开发一个类库,该类库继承自表单类,然后在Gui应用程序中显示该表单。现在我需要将类库更改为C# 在WinForm中显示UserControl,c#,C#,我正在开发一个类库,该类库继承自表单类,然后在Gui应用程序中显示该表单。现在我需要将类库更改为UserControl 如何在另一个项目的表单中显示它?提前感谢您的建议 IFaceForm是InterfaceLibrary内部的用户控件 using InterfaceLibrary; namespace MxlInterface { public partial class IFaceConn : Form { iFaceForm Interface =
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);
在表单上放置一个可以作为用户控件占位符的面板
,然后将用户控件添加到该面板中也很有用:
MyUserControl myControl = new MyUserControl();
myControlWrapperPannel.Controls.Add(myControl;
您可以通过执行以下操作直接将其添加到表单中:
MyUserControl myControl = new MyUserControl();
Controls.Add(myControl);
在表单上放置一个可以作为用户控件占位符的面板
,然后将用户控件添加到该面板中也很有用:
MyUserControl myControl = new MyUserControl();
myControlWrapperPannel.Controls.Add(myControl;
请发布您可能拥有的任何相关代码。this.Controls.Add(接口);谢谢大家,这比我想象的要简单:)你们能简单地向我解释一下为什么在类库中使用UserControl比使用表单更有益吗?请发布你们可能拥有的任何相关代码。this.Controls.Add(Interface);谢谢大家,这比我想象的要简单:)你们能简单地向我解释一下为什么在类库中使用UserControl比使用表单更有益吗?