Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save back color

Tags:

c#

winforms

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?

like image 709
Kamal Mahdavi Avatar asked Sep 28 '12 16:09

Kamal Mahdavi


People also ask

How do you remove back color?

Remove the background colorGo to Design > Page Color. Select No Color.

What is back Colour?

Description. The Background Color information is stored for image and photo files that have a color specified for the image background. The background color is, in most cases, displayed in the form of an RGB triplet or a hexadecimal code.

How do I change the background color of my text in Word?

Select the word or paragraph that you want to apply shading to. On the Home tab, in the Paragraph group, click the arrow next to Shading. Under Theme Colors, click the color that you want to use to shade your selection.

How do you add a background color in Word?

On the other hand, if you're using Word 2013 or an even newer version of Word, navigate to the Design tab in Word's toolbar. Click on Page Color in the Page Background section. Locate and click on the color you want the color of the document's background changed to.


3 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();
            }
        }
    }

enter image description here

like image 182
Hans Passant Avatar answered Sep 27 '22 19:09

Hans Passant


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.

like image 30
CrazyCasta Avatar answered Sep 27 '22 19:09

CrazyCasta


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...

like image 43
Adam Plocher Avatar answered Sep 27 '22 17:09

Adam Plocher