请问各位大虾:
    如何实现Mdi子窗体在父窗体的模式下只打开一次咧?
例如我在父窗体Form1下第一次点击打开子窗体Form2,接着第二次再点击打开Form2也不会重复出现了。

解决方案 »

  1.   

    if (ActiveMdiChild is Form1)               
                {
                    return;                        //刚不作任何处理。
                } 
                else  //如果当前窗口不是LogManage窗口
                {
                    if (this.ActiveMdiChild != null)  //若当前有活动窗口
                    {
                        this.ActiveMdiChild.Close(); //关闭所有当前活动窗口
                      }
                    Form1 F= new Form1();   //在主窗口中打开需要打开的窗体
                    F.MdiParent = this;             
                    F.Show();
                }
      

  2.   

    private  bool GetInstanceState(string Frm_Name)
    {
    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;
    }
      

  3.   


    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>();