<p>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?</p>

<p>For example:</p>

<ol>
<li>I have a user setting named <code>CellBackgroundColor</code> in <code>Properties.Settings</code>.</li>
<li>At design time I set the value of <code>CellBackgroundColor</code> to <code>Color.White</code> using the IDE.</li>
<li>User sets <code>CellBackgroundColor</code> to <code>Color.Black</code> in my program.</li>
<li>I save the settings with <code>Properties.Settings.Default.Save()</code>.</li>
<li>User clicks on the <code>Restore Default Colors</code> button.</li>
</ol>

<p>Now, <code>Properties.Settings.Default.CellBackgroundColor</code> returns <code>Color.Black</code>. How do I go back to <code>Color.White</code>?</p>

[{'answer_id': 49288, 'author': 'jfs', 'author_id': 718, 'author_profile': 'https://Stackoverflow.com/users/718', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n  <p>How do I go back to Color.White?</p>\n</blockquote>\n\n<p>Two ways you can do:</p>\n\n<ul>\n<li>Save a copy of the settings before the user changes it.</li>\n<li>Cache the user modified settings and save it to Properties.Settings before the application closes.</li>\n</ul>\n'}, {'answer_id': 49289, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 6, 'selected': True, 'text': '<p>@ozgur,</p>\n\n<pre><code>Settings.Default.Properties["property"].DefaultValue // initial value from config file\n</code></pre>\n\n<p>Example:</p>\n\n<pre><code>string foo = Settings.Default.Foo; // Foo = "Foo" by default\nSettings.Default.Foo = "Boo";\nSettings.Default.Save();\nstring modifiedValue = Settings.Default.Foo; // modifiedValue = "Boo"\nstring originalValue = Settings.Default.Properties["Foo"].DefaultValue as string; // originalValue = "Foo"\n</code></pre>\n'}, {'answer_id': 49336, 'author': 'Matt Warren', 'author_id': 4500, 'author_profile': 'https://Stackoverflow.com/users/4500', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve got round this problem by having 2 sets of settings. I use the one that Visual Studio adds by default for the current settings, i.e. <code>Properties.Settings.Default</code>. But I also add another settings file to my project "Project -> Add New Item -> General -> Settings File" and store the actual default values in there, i.e. <code>Properties.DefaultSettings.Default</code>.</p>\n\n<p>I then make sure that I never write to the <code>Properties.DefaultSettings.Default</code> settings, just read from it. Changing everything back to the default values is then just a case of setting the current values back to the default values.</p>\n'}, {'answer_id': 2117359, 'author': 'Ohad Schneider', 'author_id': 67824, 'author_profile': 'https://Stackoverflow.com/users/67824', 'pm_score': 4, 'selected': False, 'text': '<p>Reading "Windows 2.0 Forms Programming", I stumbled upon these 2 useful methods that may be of help in this context:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.reload.aspx" rel="noreferrer">ApplicationSettingsBase.Reload</a></p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.reset.aspx" rel="noreferrer">ApplicationSettingsBase.Reset</a></p>\n\n<p>From MSDN:</p>\n\n<blockquote>\n  <p>Reload contrasts with Reset in that\n  the former will load the last set of\n  saved application settings values,\n  whereas the latter will load the saved\n  default values.</p>\n</blockquote>\n\n<p>So the usage would be:</p>\n\n<pre><code>Properties.Settings.Default.Reset()\nProperties.Settings.Default.Reload()\n</code></pre>\n'}, {'answer_id': 2165493, 'author': 'Domagoj Peharda', 'author_id': 103055, 'author_profile': 'https://Stackoverflow.com/users/103055', 'pm_score': 2, 'selected': False, 'text': '<p><code>Properties.Settings.Default.Reset()</code> will reset all settings to their original value.</p>\n'}, {'answer_id': 8231413, 'author': 'expelledboy', 'author_id': 644945, 'author_profile': 'https://Stackoverflow.com/users/644945', 'pm_score': 3, 'selected': False, 'text': '<p>Im not really sure this is necessary, there must be a neater way, otherwise hope someone finds this useful;</p>\n\n<pre><code>public static class SettingsPropertyCollectionExtensions\n{\n    public static T GetDefault&lt;T&gt;(this SettingsPropertyCollection me, string property)\n    {\n        string val_string = (string)Settings.Default.Properties[property].DefaultValue;\n\n        return (T)Convert.ChangeType(val_string, typeof(T));\n    }\n}\n</code></pre>\n\n<p>usage;</p>\n\n<pre><code>var setting = Settings.Default.Properties.GetDefault&lt;double&gt;("MySetting");\n</code></pre>\n'}, {'answer_id': 14310533, 'author': 'ta.speot.is', 'author_id': 242520, 'author_profile': 'https://Stackoverflow.com/users/242520', 'pm_score': 1, 'selected': False, 'text': '<p>I found that calling <code>ApplicationSettingsBase.Reset</code> would have the effect of resetting the settings to their default values, but also saving them at the same time.</p>\n\n<p>The behaviour I wanted was to reset them to default values but not to save them (so that if the user did not like the defaults, until they were saved they could revert them back).</p>\n\n<p>I wrote an extension method that was suitable for my purposes:</p>\n\n<pre><code>using System;\nusing System.Configuration;\n\nnamespace YourApplication.Extensions\n{\n    public static class ExtensionsApplicationSettingsBase\n    {\n        public static void LoadDefaults(this ApplicationSettingsBase that)\n        {\n            foreach (SettingsProperty settingsProperty in that.Properties)\n            {\n                that[settingsProperty.Name] =\n                    Convert.ChangeType(settingsProperty.DefaultValue,\n                                       settingsProperty.PropertyType);\n            }\n        }\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49269', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/976/']