i have made a windows form.In that form i have three button RED, GREEN, PINK
when i click RED the form color goes PINK
when i click GREEN the form color goes GREEN
when i click PINK the form color goes PINK.
the problem is suppose user click PINK then form color goes pink but when the user open the same form again its comes to it default color.I want code to save the user setting.
plz help me [email protected]
Loading
Scott LyslePosted Aug 3, 2008, 1:22 AM
The easiest thing to do would be to define a user setting and use that to store and retreive the color. To create a user setting, in the solution explorer, under properties, double click on settings.settings. When the settings appear, name the setting shown to something descriptive like 'UserBackColor'. Since the type to store is a color, set the type to System.Drawing.Color. Next, set the scope to User (so the user can control the setting), and set a default value for the setting using the color picker shown when you click in the value box.
Now, since the setting is created and you want to allow the user to set the color and you want open the form back up using the color set by the user, you will need to retrieve the color in the form's constructor and set the form backcolor to that value after the initialize component call.
public Form1()
{
InitializeComponent();
this.BackColor = Properties.Settings.Default.UserBackColor;
}
And next, you will want to allow the user to set the color (and update and save the property as the same time):
private void backColorToolStripMenuItem_Click(object sender,
EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
this.BackColor = colorDialog1.Color;
Properties.Settings.Default.UserBackColor =
colorDialog1.Color;
Properties.Settings.Default.Save();
}
}