开发者

Do you have to call .Save() when modifying a application setting that is bound to a control property?

开发者 https://www.devze.com 2022-12-24 14:12 出处:网络
I am programming in .NET I have an application setting of type string. On my form I have a textbox. I bound the text property of the textbox to my application setting. If I type something in the textb

I am programming in .NET I have an application setting of type string. On my form I have a textbox. I bound the text property of the textbox to my application setting. If I type something in the textbox it changes 开发者_StackOverflow社区the value that is held in the Application setting but the next time I start the program it goes back to the default value. Do I need to call Properties.Settings.Default.Save(); after the text is entered for the new value to be saved? Shouldn't it do this automatically? Is there a way I can make it do it automatically?


Yes, you need to call Save explicitly. The binding changes the setting value in memory, but doesn't save the file


If you want it to be saved automatically, bind a handler to the TextChanged event and call Save() in it. It's just a double click and typing one line of code.


It is common practice to call Properties.Settings.Default.Save(); when close the application (for example, in FormClosing event).

0

精彩评论

暂无评论...
验证码 换一张
取 消