Reputation: 583
When I click on a button my form needs to reload, without loosing some variables.
For example:
A game needs to be reset, but the high score variable needs to be kept to count with the next one.
"Application.Reset();"
does reset the form1
, but also all the variables.
Is there a way out without using databases, because we haven't learned that yet.
Upvotes: 0
Views: 749
Reputation: 6079
It can be achieved by
1.saving the data in Database
2.XML file (Write and Read)
3.Setting the properties of Class
4.Using the Static Variables**
Upvotes: 1
Reputation: 5373
You can use Settings:
http://msdn.microsoft.com/en-us/library/bb397750.aspx
and save your data on reset/closing
Upvotes: 0
Reputation: 4768
You need to create a Class and have properties and methods in that and pass it to the form. Upon exit of the form, update your Class values with those that were changed on the form.
After that you will need to figure out "storing" the class in some sort of Stream and being able to reload your class from that stream. (XML, Binary, Protobuf, JSON) there are many ways.
Upvotes: 0