简体   繁体   中英

Settings.Default value does not change after release

I have a windows forms desktop application. I am using a settings variable in resource named Settings.Default.Code

So I set the value initial value in Form->Properties->Settings.Code="123"

And I have changed the value in application using code like this:

private void button1_Click(object sender, EventArgs e)
{
   Settings.Default.Code = "ABC";
   Settings.Default.Save();
}

After button click the Code value is same as following image

在此处输入图片说明 :

But if I get the value in code Settings.Default.Code is "ABC"

When I created a setup project and release the application, the value of this settings should be "123" but it is "ABC". The initial value is not get from first setted value. Why? How can I solve this problem?

Add this line to the beginning of your program:

Settings.Default.Reset();

More info: ApplicationSettingsBase.Reset Method

As @Peter Duniho mentioned, the problem is probably that the setting is already saved to your profile on your computer. Try to delete the config file before you test again:

C:\\Users{username}\\AppData\\Local\\{ApplicationName}

or

C:\\Users{username}\\AppData\\Roaming\\{ApplicationName}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM