C# 动态调用窗体,动态实例化窗体的方法
1 从数据库读取方法名称
using (DataClasses1DataContext con = new DataClasses1DataContext()) { string method = con.MenuFunction.Where(m => m.MenuName == treeViewEx1.SelectedNode.Text.ToString()).FirstOrDefault().method; if (method!=null) { CreateForm("OAoffice." + method, "OAoffice"); } }
2 打开窗体方法
string path = AssemblyName;//项目的Assembly选项名称 string name = strName; //类的名字 Form doc = (Form)Assembly.Load(path).CreateInstance(name); this.panel2.Controls.Clear(); doc.MdiParent = this; doc.WindowState = FormWindowState.Maximized; doc.Parent = panel2; doc.Show();