我试图在设置窗体上实现“Reset Settings”按钮。但我不希望它直到用户确定为止。Application.Settings Save()不保存实例的值(在这种情况下)
因此,我在重置它们之前创建设置的副本,并且如果用户单击取消 - 我保存这些(“旧”)设置。麻烦是 - 它不起作用。
下面是代码:
Settings s1 = Settings.Default;
s1.Setting1 = "A";
s1.Save();
Settings s2 = Clone();//A method that clones the settings
s2.Setting1 = "B";
s2.Reset();
s1.Save();//Why doesn't this line work?
s1.Reload();//Without this line - the next line shows "A" . With this line, the next shows - "ABC" (-the origianl). Why?
Text = s1.Setting1;
(超:我应该由用户来改变每次改变都设置在设置的副本,以及确认后提交的,或者我应该忽略直到用户单击确定 - 然后遍历所有控件并将每个控件的值分配给正确的属性...或者可能是其他方式?)
嗯,我会选择后者。一旦他/她确认操作,使用户更改设置生效,因此单击“取消”将只重新加载当前设置,从而避免不必要的保存和重新加载操作。 –