读取C#中的默认应用程序设置 [英] Reading default application settings in C#

查看:66
本文介绍了读取C#中的默认应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a number of application settings (in user scope) for my custom grid control. Most of them are color settings. I have a form where the user can customize these colors and I want to add a button for reverting to default color settings. How can I read the default settings?

例如:

  1. 我在 Properties.Settings 中有一个名为 CellBackgroundColor 的用户设置.
  2. 在设计时,我使用IDE将 CellBackgroundColor 的值设置为 Color.White .
  3. 用户在我的程序中将 CellBackgroundColor 设置为 Color.Black .
  4. 我使用 Properties.Settings.Default.Save()保存设置.
  5. 用户点击恢复默认颜色按钮.
  1. I have a user setting named CellBackgroundColor in Properties.Settings.
  2. At design time I set the value of CellBackgroundColor to Color.White using the IDE.
  3. User sets CellBackgroundColor to Color.Black in my program.
  4. I save the settings with Properties.Settings.Default.Save().
  5. User clicks on the Restore Default Colors button.

现在, Properties.Settings.Default.CellBackgroundColor 返回 Color.Black .如何返回 Color.White ?

Now, Properties.Settings.Default.CellBackgroundColor returns Color.Black. How do I go back to Color.White?

推荐答案

@ozgur,

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#中的默认应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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