I have a number of application settings (in user scope) for my custom grid control. Most of them are color settings. I have a form where the user can customize these colors and I want to add a button for reverting to default color settings. How can I read the default settings?
For example:
CellBackgroundColor in Properties.Settings.CellBackgroundColor to Color.White using the IDE.CellBackgroundColor to Color.Black in my program.Properties.Settings.Default.Save().Restore Default Colors button.Now, Properties.Settings.Default.CellBackgroundColor returns Color.Black. How do I go back to Color.White?
@ozgur,
Settings.Default.Properties["property"].DefaultValue // initial value from config file Example:
string foo = Settings.Default.Foo; // Foo = "Foo" by default Settings.Default.Foo = "Boo"; Settings.Default.Save(); string modifiedValue = Settings.Default.Foo; // modifiedValue = "Boo" string originalValue = Settings.Default.Properties["Foo"].DefaultValue as string; // originalValue = "Foo"
Reading "Windows 2.0 Forms Programming", I stumbled upon these 2 useful methods that may be of help in this context:
ApplicationSettingsBase.Reload
ApplicationSettingsBase.Reset
From MSDN:
Reload contrasts with Reset in that the former will load the last set of saved application settings values, whereas the latter will load the saved default values.
So the usage would be:
Properties.Settings.Default.Reset() Properties.Settings.Default.Reload()
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