Form linking issue.

Dec 22 2007 6:47 AM
Hi!

I am a beginer at C# .net and trying to learn it.

I have a form linking probelm.I have four forms form1(main form), form2,form3,form4 and i am passing data between these forms.

From form2 i am passing a string to form3 via object and displaying it in label and then another string from form3 to form4(I have to do this way because i dont want to bypass form3). This part works fine..i am opening and closing forms through the following function:


        public void open_close_form(Form frm_open, Form frm_close)
        {
            //frm_open is the form which i have to open and frm_close is the form which i have to close

            frm_open.Show();
            frm_close.Close();
            frm_close.Dispose();
           
           
        }
I come back from form4 to form3 and form3 to form4 also using this funtion.Now coming back is the problem.The problem is when i move to form4 from form3 using this function, form2 gets closed and disposed so i dont have any reference to it. On form3, i used a string from form2 which also gets disposed. Now when i come back to form3 from form4, it return me error that "object reference not set to an instance of an object". I know that why i am getting this error because form2 has already been disposed and closed so form2 object on form3 cannot get any reference to it.

I want to preserve the state of form3 when i come back to it from form4 but cannt do so because of this problem as string that was passed from from2 is not there because of form2 disposal. I want to know that is there any way that i can preserve the data that is passed on form3 to form2? i thought(not implemented) of doing this thourgh delegates but i guess i will still get this error.

any ideas? is there any better way of doing what i am doing.

any help would be appriciated.

Answers (1)