在WINFORM中,如何通过配置文件来配置窗体菜单并点击菜单能进入相应的窗体.

下面是两种方法:

第一种,适用于所有窗体都在同一个项目中

string formstring1 = @"当前命名空间的名字" + @"." + formName;//系统中窗体的名称
Type t = Type.GetType(formstring);
object obj = System.Activator.CreateInstance(t);
Form f 
= (Form)obj;
f.TopLevel 
= true;
f.ShowDialog();

 

 

第二种,适用于窗体在不同的项目中

Assembly assembly = Assembly.LoadFile(Application.StartupPath + @"\AnotherProject.dll");
object temp = assembly.CreateInstance("AnotherProject.Form1");
Type curType 
= assembly.GetType("AnotherProject.Form1"falsetrue);

object obj = System.Activator.CreateInstance(curType);
Form f 
= (Form)obj;
f.TopLevel 
= true;
f.ShowDialog();

posted on 2012-03-02 15:35  成天狂  阅读(513)  评论(0编辑  收藏  举报