Retain Back Color

How can I change and save the background color in a C # Windows application so that when I close the application and run the program again, the new color will be the default background color?

+5
source share
4 answers

You can achieve this very little. Select the form in the designer, in the "Properties" window, open the ApplicationSettings node. Select (PropertyBinding) and press the button. Select BackColor in the pop-up dialog box. Click the down arrow and click Create. Specify a name, for example, "FormBackColor".

The only thing you need is an option that allows the user to choose a different 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

+4
source

- , , .

, this.

+1

- , File.WriteAllText( "bg.txt", this.BackColor.ToString()); , this.BackColor = Color.FromName(File.ReadAllText( "bg.txt" ));

, . ...

+1

Some time ago, there was information about best practices that can be done here on stackoverflow.
Please note:
Best practice for saving application settings in a Windows Forms application

0
source

All Articles