将设置保存在 Properties.Settings.Default 中

发布于 2024-12-13 15:33:38 字数 1112 浏览 3 评论 0原文

我有一个有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溇涏 2024-12-20 15:33:38

在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文