c# - 在 C# 中读取默认应用程序设置

标签 c# .net winforms application-settings

我的自定义网格控件有许多应用程序设置(在用户范围内)。其中大部分是颜色设置。我有一个用户可以自定义这些颜色的表单,我想添加一个按钮来恢复默认颜色设置。如何读取默认设置?

例如:

  1. 我在 Properties.Settings 中有一个名为 CellBackgroundColor 的用户设置。
  2. 在设计时,我使用 IDE 将 CellBackgroundColor 的值设置为 Color.White
  3. 用户在我的程序中将 CellBackgroundColor 设置为 Color.Black
  4. 我使用 Properties.Settings.Default.Save() 保存设置。
  5. 用户点击恢复默认颜色按钮。

现在,Properties.Settings.Default.CellBackgroundColor 返回 Color.Black。我如何返回到 Color.White

最佳答案

@zgur,

Settings.Default.Properties["property"].DefaultValue // initial value from config file

例子:

string foo = Settings.Default.Foo; // Foo = "Foo" by default
Settings.Default.Foo = "Boo";
Settings.Default.Save();
string modifiedValue = Settings.Default.Foo; // modifiedValue = "Boo"
string originalValue = Settings.Default.Properties["Foo"].DefaultValue as string; // originalValue = "Foo"

关于c# - 在 C# 中读取默认应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49269/

相关文章:

c# - 如何使用 VB.Net/C# 将图像从 SQL 数据库导出到特定文件夹?

c# - 处理@@Identity 时转换无效

c# - 是否可以获取和修改文本框的标准系统上下文菜单?

c# - 如何在运行时将 IL 注入(inject)方法

.net - 如何在启动时运行一次单击一次部署的应用程序?

c# - 使用反射调用控件的 Validate() 方法

.net - UI自动化中如何调用快捷键?/。网

c# - 在应用程序的生命周期中,已编译的查询必须重新编译多少次?

c# - 属性私有(private)集崩溃统一

.net - 如何为 Amazon Simple Email Service 启用 TLS 1.1/1.2