利用反射,实现动态调用winform窗体(转)

原链接:http://www.cnblogs.com/lastgame/archive/2009/02/19/1393831.html

实用前提:在WinForm程序中,通过主窗体的Menu打开不同的窗体
我以前的做法:在Menu的Click事件中,创建打开窗体的对象实例
这样的缺点,我不说了:)
看看利用反射动态调用窗体对象的方法:

private void CreateForm(string strName)
{
this.Cursor = Cursors.WaitCursor;

string path=AssemblyName;//项目的Assembly选项名称
string name=strName; //类的名字

Form fm
=(Form)Assembly.Load(path).CreateInstance(name);
fm.MdiParent
=this.ParentForm;
fm.Show();
fm.Dock
=DockStyle.Fill;
this.Cursor = Cursors.Default;


这样的好处,也自己看吧,:)
原文地址:https://www.cnblogs.com/glacier/p/1423574.html