How can I change and save the back color in a C# Windows Application so that when I close the application and run the program again the new color will be the back color default?
-
Use a user setting http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx (old article but still applies) – lc. Sep 28 '12 at 16:18
4 Answers
You can get that going with very little effort. Select the form in the designer, in the Properties window open the ApplicationSettings node. Select (PropertyBinding) and click the button. Select BackColor in the popup dialog. Click the dropdown arrow and click New. Set the name to, say, "FormBackColor".
The only other thing you need is an option to let the user pick another color. Very easy to do with the ColorDialog class:
private void OptionChangeColor_Click(object sender, EventArgs e) {
using (var dlg = new ColorDialog()) {
if (dlg.ShowDialog() == DialogResult.OK) {
this.BackColor = Properties.Settings.Default.FormBackColor = dlg.Color;
Properties.Settings.Default.Save();
}
}
}

- 922,412
- 146
- 1,693
- 2,536
-
It is in my answer: `Set the name to, say, "FormBackColor".` Follow the steps as I described them. – Hans Passant Sep 28 '12 at 18:56
-
Sorry Sir, But I am beginner and I can not find "ApplicationSettings node" and also "PropertyBinding. and what is Popup dialog I think you are master of C# – Kamal Mahdavi Sep 28 '12 at 19:24
-
You'll need to save the new color in some file that you load on startup and apply as the background color.
Or use a user setting like this.

- 26,917
- 4
- 45
- 72
You could do something simple like File.WriteAllText("bg.txt", this.BackColor.ToString()); and when the app loads do this.BackColor = Color.FromName(File.ReadAllText("bg.txt"));
Of course storing this color in Isolated Storage or in the registry might be better. But you get the idea...

- 13,994
- 6
- 46
- 79
-
but I have this error when I wanna use in form load "Control does not support transparent background colors" – Kamal Mahdavi Sep 28 '12 at 17:22
Some time ago there was thread about best practices to do that here on stackoverflow.
Please take look:
Best practice to save application settings in a Windows Forms Application