日期:2014-05-17 浏览次数:20742 次
ToolStripMenuItem tsi = sender as ToolStripMenuItem;//得到事件源,强转为菜单项
Assembly asb = Assembly.GetExecutingAssembly();//得到当前的程序集
Form f = (Form)asb.CreateInstance("Test." + tsi.Tag.ToString());//利用反射,根据数据库中的字段值创建窗体对象
foreach (System.Windows.Forms.Form ff in pnc_info.Controls)
{
//如果子窗体存在,激活子窗体
if (ff.Name == f.Name)
{
ff.WindowState = System.Windows.Forms.FormWindowState.Minimized;
ff.Activate();
ff.Size = ff.Parent.Size;
ff.WindowState = System.Windows.Forms.FormWindowState.Maximized;
return;
}
}
f.TopLevel = false; //设置属性
f.Show(); //显示form
public virtual Object CreateInstance(
string typeName,
bool ignoreCase,
&