0
votes

I'm Using Visual Studio 2010 And I'm troubling with a problem in my project right now . this question you may feel like foolishness . But i don't know what happening.

In my Project there are 3 forms .

  • Form1
  • Form2
  • DisplayFrm

I was trying to Open a form(DisplayFrm) using two Other forms(Form1 and Form2)

This is the code That i used to open the "DisplayFrm" using Both "Form1" and "Form2"

        DisplayFrm.InitialLoadCustProf = RegCustIDtextBox.Text;
        DisplayFrm frm = new DisplayFrm();
        frm.ShowDialog();
  • I have Opened "DisplayFrm" Using From1
  • After Doing some Operations Over there I have Closed that Form using [X] button in Title bar.
  • (Also i have tried by giving this.Close(); in a separate button)

The problem is that ,when i am opening DisplayFrm agian using Form2 ,it's not starting as a fresh form . it simply restoring the DisplayFrm which i have already Closed Before with the Operations i have done Already.

  • I don't have this trouble with any other project . I think my project crashed ..it does not showing any kind of error.
  • is there any way to use this.dispose(); with form Closing event?.Currently that not working Fine .
  • Why my Form is not Getting Closed ? . Why it is behaving like i have used this.hide(); and this.show(); ?
1
Do you use some kind of static variables inside the DisplayForm class? Are these variables (if any) involved in keeping the state of work done in the DisplayForm? And finally are you creating a new DisplayForm() inside the form2 code?Steve

1 Answers

1
votes

DisplayFrm.InitialLoadCustProf seems to be static. Try to change it to an instance property and open the form like this:

using( DisplayFrm frm = new DisplayFrm() )
{
    frm.InitialLoadCustProf = RegCustIDtextBox.Text;
    frm.ShowDialog( this );
}