111,093
社区成员




private void Item_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = sender as ToolStripMenuItem;
this.Cursor = Cursors.WaitCursor;
string path = "FastERP";//项目的Assembly选项名称
string name = "FastERP.IU.UUnit"; //类的名字
Form fm = (Form)Assembly.Load(path).CreateInstance(name);
fm.MdiParent = this.ParentForm;
//panel3.Controls.Add(fm);
fm.Show();
fm.Dock = DockStyle.Fill;
this.Cursor = Cursors.Default;
}
namespace FastERP.UI
{
public partial class UUnit : Form
{
public UUnit()
{
InitializeComponent();
}
}
}
string path = "FastERP";//项目的Assembly选项名称
string name = ".UUnit"; //类的名字
//实际上它就是:
string frm Path = Assembly.GetExecutingAssembly().GetName().Name + ".UUnit";
//获取当前程序集
Assembly assembly = Assembly.GetExecutingAssembly();
Type objType = assembly.GetType(frmPath);
if (objType != null)
Form frm = (Form)Activator.CreateInstance(objType);
//最后再加载到mainForm
……
很明显,用法错了。
Assembly.Load("程序集名称").CreateInstance("命名空间.类")
要先获取当前程序集,再进行实例化。