将设置保存在 Properties.Settings.Default 中
我有一个有 6 个倒计时器的应用程序。我希望应用程序存储当前的结束时间,这样万一计算机关闭,日期将被保存并且不会丢失任何内容。
我的问题是应用程序正在保存日期,但是当再次启动应用程序时,它会重新加载默认设置而不是保存的设置。
这是我所拥有的
public MainWindow()
{
InitializeComponent();
SetupTimer(timer0, watch0_0Time, watch0_0Border);
SetupTimer(timer1, watch0_1Time, watch0_1Border);
SetupTimer(timer2, watch0_2Time, watch0_2Border);
SetupTimer(timer3, watch1_0Time, watch1_0Border);
SetupTimer(timer4, watch1_1Time, watch1_1Border);
SetupTimer(timer5, watch1_2Time, watch1_2Border);
timer0.countTo = Properties.Settings.Default.Timer0Date;
timer1.countTo = Properties.Settings.Default.Timer1Date;
timer2.countTo = Properties.Settings.Default.Timer2Date;
timer3.countTo = Properties.Settings.Default.Timer3Date;
timer4.countTo = Properties.Settings.Default.Timer4Date;
timer5.countTo = Properties.Settings.Default.Timer5Date;
}
......
我稍后会通过这个电话保存
Properties.Settings.Default.Timer0Date = timer.countTo;
我希望你能提供帮助:D
I have a application which has 6 count down timers. I want the application to store the current end time so in case the computer will shut down, the date will be saved and nothing is lost.
My problem is that the application is saving the date, but when starting the application again it reloads the default settings and not the saved settings.
Here is what I have
public MainWindow()
{
InitializeComponent();
SetupTimer(timer0, watch0_0Time, watch0_0Border);
SetupTimer(timer1, watch0_1Time, watch0_1Border);
SetupTimer(timer2, watch0_2Time, watch0_2Border);
SetupTimer(timer3, watch1_0Time, watch1_0Border);
SetupTimer(timer4, watch1_1Time, watch1_1Border);
SetupTimer(timer5, watch1_2Time, watch1_2Border);
timer0.countTo = Properties.Settings.Default.Timer0Date;
timer1.countTo = Properties.Settings.Default.Timer1Date;
timer2.countTo = Properties.Settings.Default.Timer2Date;
timer3.countTo = Properties.Settings.Default.Timer3Date;
timer4.countTo = Properties.Settings.Default.Timer4Date;
timer5.countTo = Properties.Settings.Default.Timer5Date;
}
....
I am saving later with this call
Properties.Settings.Default.Timer0Date = timer.countTo;
I hope you can help :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 C# 中,您必须调用 Properties.Settings.Default。保存()。与 VB 不同,在 C# 中,设置值更改后不会自动保存。
In c#, you have to call Properties.Settings.Default.Save(). Otherwise than in VB, in c#, the settings will not be saved automatically after a value change.