Reputation: 26547
Hi How can I save 2 last winform state? I use it when user clicks on "cancel" button. I wanna to set the form state into its proper one.
Thank you
Upvotes: 1
Views: 236
Reputation: 12316
Create a new instance of the form each time you need it.
If you can't create an instance of the form every time you could consider using a user control that you instanciate instead.
Part from that if you are using WPF you could bind GUI directly to datastructure.
In WinForms you can bind directly to some controls such as Grid/PropertyList/etc.
You can use Reflection to automaticaly iterate through the forms controls, but that is a bit complex.
Upvotes: 0
Reputation: 16613
You can save values of all relevant controls to the application configuration file, for example in FormClosing event (you'd need to create the properties yourself)
Properties.Settings.Default.textA = textBoxA.Text;
and restore them on form onLoad event
textBoxA.Text = Properties.Settings.Default.textA;
Upvotes: 1