public class static FormFactory { public static T CreateOrGetOpenForm<T>(params object[] createParams) where T : Form { Type formType = typeof(T); foreach (Form item in Application.OpenForms) { if (item.GetType() == formType) { return (T)item; } } return (T)Activator.CreateInstance(typeof(T), createParams); } } 使用Form1 form1 = FormFactory.CreateOrGetOpenForm<Form1>();
{
return; //刚不作任何处理。
}
else //如果当前窗口不是LogManage窗口
{
if (this.ActiveMdiChild != null) //若当前有活动窗口
{
this.ActiveMdiChild.Close(); //关闭所有当前活动窗口
}
Form1 F= new Form1(); //在主窗口中打开需要打开的窗体
F.MdiParent = this;
F.Show();
}
{
int Children_Count=this.MdiChildren.Length;
for(int i=0;i<Children_Count;i++)
{
if(this.MdiChildren[i].WindowState==FormWindowState.Maximized )
this.MdiChildren[i].WindowState=FormWindowState.Normal;
}
int Children_Count=this.MdiChildren.Length;
for(int i=0;i<Children_Count;i++)
{
if (this.MdiChildren[i].Name==Frm_Name )
{
this.MdiChildren[i].WindowState=System.Windows.Forms.FormWindowState.Normal;
this.MdiChildren[i].Focus();
return true;
}
}
return false;
}
public class static FormFactory
{
public static T CreateOrGetOpenForm<T>(params object[] createParams) where T : Form
{
Type formType = typeof(T);
foreach (Form item in Application.OpenForms)
{
if (item.GetType() == formType)
{
return (T)item;
}
}
return (T)Activator.CreateInstance(typeof(T), createParams);
}
}
使用Form1 form1 = FormFactory.CreateOrGetOpenForm<Form1>();