运行时 AppSettings.settings 编辑器对话框 [英] Runtime AppSettings.settings editor dialog

查看:42
本文介绍了运行时 AppSettings.settings 编辑器对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我正在寻找这种类型的项目:http://www.codeproject.com/Articles/6160/应用程序配置编辑器使用属性

Essentially I'm looking for this type of project: http://www.codeproject.com/Articles/6160/Application-Configuration-Editor-using-the-Propert

但是对于应用程序设置.你听说过吗,你有什么建议吗?

But for the Application Settings. Have you heard of it, could you advice anything?

基本上用例是,一旦设置,AppSettings 只能从代码中更改,如果您想手动更改任何内容,您的选择非常有限且复杂.

Basically the usecase is that once set, AppSettings could be changed only from the code and if you want to change anything by hand, you've got very limited and complex options.

这个想法是允许用户使用--config"参数运行应用程序,并允许他更改类似于 Visual Studio 自己的编辑器的界面中的任何设置:

The idea is to allow user to run the app with '--config' parameter and to allow him to change any setting there is in the interface that resembles Visual Studio's own editor:

编辑:当然,在运行时唯一可编辑的列应该是值.唯一可见的应该是名称,如下所示:

Edit: of course, in runtime the only editable column should be Value. And the only other visible one should be Name, like here:

推荐答案

哦,没想到,把你的ApplicationSettingsBase放到PropertyGrid.SelectedObject中就行了可以编辑它.然后您只需调用 .Save() 并保存您的设置.

Oh, haven't thought of it, just put your ApplicationSettingsBase into PropertyGrid.SelectedObject and you can edit it. Then you just call .Save() and your settings are saved.

就这么简单.

编辑:如果您正在构建这样的编辑器,请考虑添加使用 .Reset() 方法将设置重置为其默认值的按钮.默认情况下,我指的是您在 Visual Studio 的设计器编辑器中指定的值.

Edit: If you're building such an editor, consider adding the button that resets settings to their default values with the .Reset() method. By defaults I mean values that you specified in designer editor in Visual Studio.

使用此按钮有两个主要问题:

With this button there're two main gotcha's:

首先,在调用.Reset()之后,新的(默认)设置已经保存到磁盘,所以不会有明显> 恢复它们的方法(如果有的话).所以,请让您的用户为此做好准备.

First, after .Reset() is called, new (default) settings are already saved to disk, so there will be no obvious way of recovering them (if any at all). So, please, prepare your user for that.

其次,您需要在 PropertyGrid 上调用 .Refresh(),因为它不会刷新其字段(但是当您将光标设置为字段,它会刷新,所以数据没有保存,它只是仍然绘制在控件上).

Secondly, you'll need to call .Refresh() on your PropertyGrid, because it wouldn't refresh its fields (but when you'll set cursor to the field, it will refresh, so data is not saved, it's just still painted on the control).

另一个编辑:为了使编辑设置的过程更加用户友好,您可能希望将它们组织成组,将名称更改为更具可读性等.

Another edit: To make the process of editing settings even more user-friendly, you would probably want to organize them in groups, change names to more readable and such.

不幸的是,设置对象的代码是自动生成的,这意味着您无法向该类中的属性添加任何属性.幸运的是,您可以以编程方式添加这些属性.

Unfortunately code for the settings object is autogenerated, which means that you can't add any attributes to the properties in that class. Fortunately, you can add these properties programmatically.

这篇关于运行时 AppSettings.settings 编辑器对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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