我的自定义网格控件有许多应用程序设置(在用户范围内)。其中大部分是颜色设置。我有一个用户可以自定义这些颜色的表单,我想添加一个按钮来恢复默认颜色设置。如何读取默认设置?
例如:
- 我在
Properties.Settings
中有一个名为CellBackgroundColor
的用户设置。 - 在设计时,我使用 IDE 将
CellBackgroundColor
的值设置为Color.White
。 - 用户在我的程序中将
CellBackgroundColor
设置为Color.Black
。 - 我使用
Properties.Settings.Default.Save()
保存设置。 - 用户点击
恢复默认颜色
按钮。
现在,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/