I have an application with some textboxes. My user fills the textboxes and runs some methods, when they close the application data is lost (normally).
I want to keep the value of a couple of textboxes and some local variables. It's not worth it to use database
, and simple .txt
files are not clean enough, is there any other simple and brief way of storing little volumes of data between application runs?
I'm not sure but have heard some wisps about resource files, are they good for this case?
Simplest way is binding your textboxes to application settings:
FormClosed
event save application settingsSaving settings:
private void Form_FormClosed(object sender, FormClosedEventArgs e)
{
Settings.Default.Save();
}
Next time when user will start your application, settings will be loaded from user-specific file, and textboxes will be filled with same data as it was before user closed an application last time.
Also in application settings you can store local variables, but you will have to add settings for them manually, and manually read that setting on application start:
var x = Settings.Default.MyCounter
Settings.Default.MyCounter = x
just before calling Settings.Default.Save()
There are a couple of options, but with most of them, you're going to be putting a file somewhere, whether it's a text file, resources/config or binary.
Using settings is one option: http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C
You can also take the serialization route: http://msdn.microsoft.com/en-us/library/vstudio/et91as27.aspx
Or you could possibly look into noSQL databases like MongoDB: http://www.mongodb.org/
You have the following options
A local Microsoft Access database which can store small footprint.
Use a Dictionary, Serialize / Deserialize to filesystem.
The Windows registry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With