非顶级窗体不能显示为模式对话框。在调用 showDialog 之前应从所有父窗体中移除该窗体。

解决方案 »

  1.   

    判断该窗提是否已经存在,存在就RETURN
      

  2.   

    子窗体体设置成父窗体的全局变量,在要显示的时候加个判断:
    比如子窗体名为childForm
    if(childForm == null)
    {
        childForm = new ChildForm();
    }
    childForm.show();
    或者直接用ShowDialog()
      

  3.   

    7楼的对,
    用ShowDialog()简单点
      

  4.   

    无法访问已释放的对象。
    对象名:“InsertData”。7楼的大哥,别忽悠我行不?第一次那样是不多弹了,可我关了再按文件,就异常````
    代码写死了啊
      

  5.   

    楼主大哥,你的InsertData是怎么定义的?要把它作为类的变量,而不是属于某个方法的局部变量。
      

  6.   

    你新建一个Form,你看看它的代码,如果没有Windows窗体的设计代码,那就是我错了
      

  7.   

    mCh =new frmChild;
    if (mCh.Created)
    {
      mCh.BringToFront();
    }
    else
    {
      mCh = new frmChild();
      mCh.MdiParent = 父窗体;
      mCh.Show();
    }
      

  8.   

    写错一点,补充一下。
    frmChild mCh =new frmChild(); 
    if (mCh.Created) 

      mCh.BringToFront(); 

    else 

      mCh = new frmChild(); 
      mCh.MdiParent = 父窗体; 
      mCh.Show(); 

      

  9.   

    public partial class frmMain : Form
    {
           .........
           frmChild mCh =new frmChild(); //是这里先定义一下。
    }以下代码是在frmMain里打开子窗体时使用。
    if (mCh.Created)  
    {  
      mCh.BringToFront();  
    }  
    else  
    {  
      mCh = new frmChild();  
      mCh.MdiParent = this;  
      mCh.Show();  
    }  
      

  10.   

    可以写这样一个方法解决问题,其中第一个参数是 mdi 父窗体,第二个参数是 mdi 子窗体的name属性。
    private void ShowSubForm(Form ParentForm, string SubFormName)
            {
                Form childForm;
                bool flag = false;            if (ParentForm.MdiChildren.Length != 0)
                {
                    int childCount = ParentForm.MdiChildren.Length;
                    for (int i = 0; i < childCount; i++)
                    {
                        childForm = ParentForm.MdiChildren[i];
                        if (childForm.Name == SubFormName)
                        {
                            flag = true;
                            childForm.Activate();
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    childForm = (Form)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("在这里写命名空间名称" + SubFormName);
                    if (childForm == null)
                    {
                        MessageBox.Show("没有找到窗口!");
                        return;
                    }
                    childForm.MdiParent = ParentForm;
                    childForm.Show();
                }
            }
    然后调用该方法就可以了。