一路向前走

其中的代码,如果您有更好的改进,请一定提出您的宝贵意见及建议

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

在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 2010-05-20 22:33  Adair  阅读(819)  评论(3编辑  收藏  举报