如题 
我用了一个公共类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace MDI
{
    class Class
    {
        public static Form2 first = null;
        public static Form3 second = null;
        public static Form4 third = null;
    }
}
在父窗体中怎样判断某一子窗体是否存在

解决方案 »

  1.   


            //定义公共方法:遍历子窗体
            public void showchildform(Form childform)
            {
                isopened = false;  //子窗体是否打开
                Form[] frm = this.MdiChildren;  //将所有打开的子窗体放入数组
                if (frm.Length == 0)  //如果没有打开的子窗体
                {
                    //进行你想要的操作,下面的代码是如果子窗体没打开那么打开子窗体
                    childform.MdiParent = this;
                    childform.Show();
                }
                else   //如果有子窗体存在
                {
                    foreach (Form f in frm)   //遍历子窗体
                    {
                        if (f.Name == childform.Name)   //如果是要激活的子窗体
                        {
                            f.Activate();   //使该子窗体活动
                            isopened = true;
                            break;
                        }
                    }
                    if (isopened == false)   //如果指定的子窗体没有打开
                    {
                        //进行你想要的操作,下面的操作时打开子窗体
                        childform.MdiParent = this;
                        childform.Show();
                    }
                }
            }
      

  2.   

    直接调用
    if (first==null || first.IsDisposed())
     
    {
       MessageBox.Show("不存在");
    }