- #1
- 371
- 0
In VB6 this was very easy. you just used
In c# you have to do this
When I put this in a button it worked, but every time I changed forms it reset the form values to default (e.g. text boxes would become blank etc).
I was told this create a new instance every time, which was then lost so it would create a new instance every time with default values. So it put the form2 openForm2 = new form2(); at the top of the form code and have only kept the form2.show(); and this.hide(); in the button click.
The problem I now have is that because I need to declare an instance of each of my three forms I am causing a stack overflow.
How can I show and hide forms without the data disappearing? Where should I create these instances?
Code:
form1.hide
form2.show
In c# you have to do this
Code:
form2 openForm2 = new form2(); //create a new instance
form2.show();
this.hide();
When I put this in a button it worked, but every time I changed forms it reset the form values to default (e.g. text boxes would become blank etc).
I was told this create a new instance every time, which was then lost so it would create a new instance every time with default values. So it put the form2 openForm2 = new form2(); at the top of the form code and have only kept the form2.show(); and this.hide(); in the button click.
The problem I now have is that because I need to declare an instance of each of my three forms I am causing a stack overflow.
How can I show and hide forms without the data disappearing? Where should I create these instances?