我有一个父窗体 form ,他有两个子窗体,child1,child2. 点击form上的菜单menu1出现child1,点击menu2出现child2。切换没问题,关键是当关闭子窗体后,再去点击菜单打开的时候会出现错误代码是:
private void form_main_Load(object sender, System.EventArgs e)
{
//初始化窗口1
child1.MdiParent = this;
child1.FormBorderStyle = FormBorderStyle.FixedDialog;
child1.WindowState =  System.Windows.Forms.FormWindowState.Maximized; 
child1.Show();
////初始化窗口2
child2.MdiParent = this;
child2.FormBorderStyle = FormBorderStyle.FixedDialog;
child2.WindowState =  System.Windows.Forms.FormWindowState.Maximized; 
child2.Show();
                      }private void menu1_Click(object sender, System.EventArgs e)
{
child1.Visible = true;
child1.Show();   //这句有没有都会出现
child1.Activate();
                   }
具体信息是:
未处理的“System.ObjectDisposedException”类型的异常出现在 system.windows.forms.dll 中。
其他信息: 无法访问名为“Form1”的已处置对象。请问,如何判断窗体是否关闭了?

解决方案 »

  1.   

    child1,child2再你关闭两个窗口时被释放了
      

  2.   

    private void form_main_Load(object sender, System.EventArgs e)
    {

                          }private void menu1_Click(object sender, System.EventArgs e)
    { //初始化窗口1
    child1.MdiParent = this;
    child1.FormBorderStyle = FormBorderStyle.FixedDialog;
    child1.WindowState =  System.Windows.Forms.FormWindowState.Maximized; 
    child1.Show();
    ////初始化窗口2
    child2.MdiParent = this;
    child2.FormBorderStyle = FormBorderStyle.FixedDialog;
    child2.WindowState =  System.Windows.Forms.FormWindowState.Maximized; 
    child2.Show(); child1.Visible = true;
    child1.Show();   //这句有没有都会出现
    child1.Activate();
                       }