Reputation: 11
I wrote .net code and want anyone to help me and tell if this is right or not :). I made a form with two checkboxes and two picture boxes and a button and want to save values of the checkbox and the picture box when I close the form and reload these values again after rerun.
The code I wrote:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//this.BackColor = Properties.Settings.Default.UserBackColor;
Properties.Settings.Default.Reload();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
pictureBox1.Image = Image.FromFile("C:\\red.jpg");
Properties.Settings.Default.Upgrade();
}
}
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Save();
Application.Exit();
}
Upvotes: 1
Views: 67
Reputation: 6372
The use of Upgrade()
is incorrect here. It is used to update settings after an application upgrade.
Remove that line and everything should work fine and dandy.
There's a nice short article on CodeProject that explains the use of application settings: http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C
Upvotes: 1