In Visual Studio:
1. open the Solution Explorer
2. under the Properties tab
3. double-click Settings
define a Setting there, select type 'User, select the type 'Color from the dropdown.
assume you created a Color Setting named 'MainFormBackColor.
I. to set that property:
private void Form1_Load(object sender, EventArgs e)
{
Properties.Settings.Default.MainFormBackColor = this.BackColor;
}
2. to change the value of that setting using a ColorDialog:
private void button1_Click(object sender, EventArgs e)
{
Color currentSavedColor = (Color) Properties.Settings.Default.MainFormBackColor;
Color selectedColor;
colorDialog1.Color = currentSavedColor;
if (colorDialog1.ShowDialog(this) == DialogResult.OK)
{
selectedColor = colorDialog1.Color;
if(MessageBox.Show(string.Format("Change current MainFormBackgroundColor?\r\nfrom: {0}\r\nto: {1}", currentSavedColor, selectedColor), "Color Change", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
this.BackColor = selectedColor;
Properties.Settings.Default.MainFormBackColor = selectedColor;
}
}
}
Note:
1. back when, we used to have use this syntax: Properties.Settings.Default["MainFormBackColor"], but now we can use the syntax shown here (I believe the new syntax was introduced with .NET 3.5). But, the old syntax still works.
And, now go and study what happens if you make the Setting you created 'Application in scope, rather than 'User. Then, examine using the 'config file to persist settings, and, then, read articles here on CodeProject about strategies for saving big bunches of state information by serializing and de-serializing.