读取C#中的默认应用程序设置 [英] Reading default application settings in C#
本文介绍了读取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?
例如:
- 我在
Properties.Settings
中有一个名为CellBackgroundColor
的用户设置. - 在设计时,我使用IDE将
CellBackgroundColor
的值设置为Color.White
. - 用户在我的程序中将
CellBackgroundColor
设置为Color.Black
. - 我使用
Properties.Settings.Default.Save()
保存设置. - 用户点击
恢复默认颜色
按钮.
- I have a user setting named
CellBackgroundColor
inProperties.Settings
. - At design time I set the value of
CellBackgroundColor
toColor.White
using the IDE. - User sets
CellBackgroundColor
toColor.Black
in my program. - I save the settings with
Properties.Settings.Default.Save()
. - 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屋!
查看全文