简述
功能新增与修改可能性很大,但是整个展示的框架一般不会变动,动态加载就能满足需要的应用场景。
软件框架
左侧与顶部作为菜单显示栏,右下区域全部作为展示界面,此区域作为动态加载父窗口。
整个界面框架大致如下:
动态加载界面
动态库
建立控件项目,设计一个想要的界面,编译成动态库,这里就拿以前的串口控件
加载动态库
string dllPath = "";
public LoadDll(string dllpath)
{
dllPath = dllpath; //动态库路径
}
public object LoadInstance(string class_name)
{
Assembly assem = Assembly.LoadFile(dllPath);
Type[] tys = assem.GetTypes();//只好得到所有的类型名,然后遍历,通过类型名字来区别了
foreach (Type ty in tys)//huoquleiming
{
if (ty.Name == class_name)
{
ConstructorInfo constructor = ty.GetConstructor(Type.EmptyTypes);
object ClassObject = constructor.Invoke(new object[] { });//实例化
return ClassObject;
}
}
return null;
}
加载界面
LoadDll ld = new LoadDll(System.AppDomain.CurrentDomain.BaseDirectory + "串口控件.dll");
Intervening_Variable.userctl_1 = (UserControl)ld.LoadInstance("UserControl1");
Intervening_Variable.userctl_1.Dock = DockStyle.Fill;
panel_workare.Controls.Add(Intervening_Variable.userctl_1);
Intervening_Variable.userctl_1.BringToFront();
Intervening_Variable.userctl_1.Show();