怎么将很多窗体变成MDI窗体的子窗体
我首先设置了主窗体的ISMDIContainer属性为true,我想启动的时候很多窗体就是它的子窗体
目前用代码for (int k = 0; k < this.MdiChildren.Length; k++)查找子窗体时,发现this.MdiChildren.Length=0,没有子窗体
[解决办法]
//show MDIchild
public void ShowChild(string childFullName)
{
if (!IsExist(childFullName))
{
Type type = Type.GetType(childFullName);
if (type != null)
{
object obj = Activator.CreateInstance(type);
Form child = (Form)obj;
child.MdiParent = this;
child.Dock = DockStyle.Fill;
child.Show();
childFormList.Add(child);
}
}
else
{
Form existForm = childFormList.Find(form => (form.GetType().ToString() == childFullName));
existForm.Activate();
}
}
// if child has been created
public bool IsExist(string childFullName)
{
foreach (Form f in childFormList)
{
if (f.GetType().ToString() == childFullName)
return true;
}
return false;
}
谢谢,可能没这么简单,可能我需要的是利用反射生成子窗体,比如有十几个子窗体只选择性打开几个,如果增加到几十个窗体,那怎么办?
子窗体是在运行时设定的:
childForm.MdiParent = mainForm;
childForm.Show();