So, I have Form called Preferences with TabControl
in it. This TabControl
contains several TabPages
(General, Advanced, Misc, ...) with few comboboxes, checkboxes and labels. Each of this control inside TabPage is assigned Application Settings Property Binding (aka they show saved user settings, user can change them etc...).
I know that there is a method to reset all settings (Properties.Settings.Default.Reset();
), but is there a way how to reset only settings inside one TabPage
?
My solution is to iterate thru controls in TabPage, check if it is combobox, label etc and then reset it´s value to default, but is there a "oneliner" solution to this ?
The
ApplicationSettings
doesn't have built-in support to reset just some properties. But to solve the problem, you can use either of these options:Create a method which resets all bound controls of a
TabPage
Using Multiple Settings Files with Designer Support
Option 1 - Create a method which resets all bound controls of a TabPage
You can create a method which look at controls of the tab page and check if it's bound to application settings, find the property in settings and reset its value to the default value. Then you can reset settings of a
TebPage
width one line of code:ResetSettings(tabPage1);
.Here is the method:
Option 2 - Using Multiple Settings Files with Designer Support
If the reason of using a single settings file is because of designer support, you should know you can have designer support also with multiple settings files. Then you can use different settings files and reset each settings group separately. You can simply encapsulate them in a single class using such code:
To reset a setting group it's enough to call
MySettings.General.Reset();
To reset all settings, you can call
MySettings.ResetAll();
Note for design-time support
To have designer support for binding properties to settings, create multiple settings files in root of your project. Don't put settings files in folders. The setting picker, only shows
Settings.settings
file which is inProperties
folder and those files which are in root of project. This way you can see different settings files and settings properties in a tree-view like this:Try this: