Bug ( disposed object)

Feb 9 2010 5:30 AM
when user clicks on this event <CreateToolStripMenuItem > ,CR  shows the form ,but when you close this form and wanna 
reopen it  ,below  error occurs 
<< ObjcetDisposedException  was unhandled  "cannot  access  a disposed object." >>

where shall I get the instace of  the object (CR) ?
pay attention that I used  the FormClosedEventHandler .
this is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Mini_dbms
{
    public partial class Form1 : Form
    {
        CreateDB.Form2 CR = new CreateDB.Form2();
        
        public Form1()
        {
            InitializeComponent();
        }

        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void CreateToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            //CreateDB.Form2 CR = new CreateDB.Form2(); 
            CR.Show();    //  error in here  while reopenig it<< ObjcetDisposedException  was unhandled  "cannot  access  a disposed object." >> 
       
        }

        private void Main_Load(object sender, EventArgs e)
        {
            
            CR.FormClosed += new FormClosedEventHandler(CR_FormClosed);
           
        }

        void CR_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (CR.flag == 1)
            {
                toolStripStatusLabel1.Text = "successfully created!";
                
            }
            else if(CR.flag==2)
            {
                toolStripStatusLabel1.Text = "Creation failed !";
            }
            
        }
    }
}


Answers (1)