[英]Do you have to call .Save() when modifying a application setting that is bound to a control property?
I am programming in .NET I have an application setting of type string. 我在.NET中编程,我的应用程序设置为字符串类型。 On my form I have a textbox. 在我的表单上,我有一个文本框。 I bound the text property of the textbox to my application setting. 我将文本框的text属性绑定到我的应用程序设置。 If I type something in the textbox it changes 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();
我是否需要调用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. 是的,您需要显式调用Save
。 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. 如果要自动保存它,请将处理程序绑定到TextChanged事件并在其中调用Save()。 It's just a double click and typing one line of code. 只需双击并输入一行代码即可。
It is common practice to call Properties.Settings.Default.Save();
常见的做法是调用Properties.Settings.Default.Save();
when close the application (for example, in FormClosing
event). 当关闭应用程序时(例如,在FormClosing
事件中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.