C#如何正确保存? [英] C# how do I save this to settings correctly?

查看:113
本文介绍了C#如何正确保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以对于我的程序,我允许用户自定义程序中所有内容的颜色,所以我做了这个功能。

并保存用户设置。

但是每当程序重新开始工作时,它都没有任何帮助吗?

So for my program I'm allowing the Users to customize the color of everything in the program so I made this function that does it.
and saves the Users settings.
But whenever the program Restarts for it to work like that, it doesn't work any help?

SeaInject.Properties.Settings.Default.Color = this.colorDialog1.Color;
SeaProject.Properties.Settings.Default.Save();
this.metroButton1.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton2.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton3.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton4.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton5.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton6.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton7.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroButton8.BackColor = SeaProject.Properties.Settings.Default.Color;
this.metroComboBox1.BackColor = SeaProject.Properties.Settings.Default.Color;
Application.Restart();





我的尝试:



将设置设置为应用程序设置,但它使其成为只读。

尝试base.Refresh();



What I have tried:

Setting the Setting as a Application setting but it made it read only.
tryed "base.Refresh();"

推荐答案

Application.Restart()将从DLL文件中的默认值重启应用程序,并且所有内存中的更改都将失效。



尝试将默认颜色保存到配置文件并在启动时设置颜色。
Application.Restart() will restart the application from defaults in the DLL files and all your in-memory changes will be invalidated.

Try saving your default color to a config file and setting the colors on startup.


这篇关于C#如何正确保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆