/ Published in: C#
Read the [best article on the subject - Exploring Secrets of Persistent Application Settings](http://www.devx.com/dotnet/Article/33944/1954) - and then the following links if desired. (Note, I recommend reading [this forum post about settings not being upgraded](http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/790980e8-eb89-492c-976b-4f93dc7c1caf/).)
It might help to understand [What is app.config for?](http://stackoverflow.com/questions/1431742/what-is-app-config-for)
Also of note: [Saving out a Form's Size and Location using the Application Settings feature](http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx). Be sure to read the first couple of comments as well.
Lastly, if you are interested in import/export functionality, check out [my post on the subject](http://stackoverflow.com/questions/2389290/how-to-load-a-separate-application-settings-file-dynamically-and-merge-with-curre).
It might help to understand [What is app.config for?](http://stackoverflow.com/questions/1431742/what-is-app-config-for)
Also of note: [Saving out a Form's Size and Location using the Application Settings feature](http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx). Be sure to read the first couple of comments as well.
Lastly, if you are interested in import/export functionality, check out [my post on the subject](http://stackoverflow.com/questions/2389290/how-to-load-a-separate-application-settings-file-dynamically-and-merge-with-curre).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// See URLs. Below is some of the important code. // Save a toolstrip's information: private void MainForm_FormClosing(object sender, FormClosingEventArgs e) ToolStripManager.SaveSettings(this); Properties.Settings.Default.Save(); . . . } private void MainForm_Load(object sender, EventArgs e) { ToolStripManager.LoadSettings(this); ... } // To discard changes during the current session: Properties.Settings.Default.Reload(); // To restore settings to "out-of-the-box": Properties.Settings.Default.Reset(); // Maintaining settings between versions if (Properties.Settings.Default.UpgradeSettings) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeSettings = false; Properties.Settings.Default.Save(); } // You will also need to create the referenced setting (UpgradeSettings) and initialize it to True. // Saving a form's location and size private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Properties.Settings.Default.MyState = this.WindowState; if (this.WindowState == FormWindowState.Normal) { Properties.Settings.Default.MySize = this.Size; Properties.Settings.Default.MyLoc = this.Location; } else { Properties.Settings.Default.MySize = this.RestoreBounds.Size; Properties.Settings.Default.MyLoc = this.RestoreBounds.Location; } Properties.Settings.Default.Save(); } private void Form1_Load(object sender, EventArgs e) { this.Size = Properties.Settings.Default.MySize; this.Location = Properties.Settings.Default.MyLoc; this.WindowState = Properties.Settings.Default.MyState; }
URL: http://www.devx.com/dotnet/Article/33944/1954