应用程序中的Visual C#“设置编辑器”?

时间:2022-09-20 15:54:26

Is there an easy way to wrap a "Preferences Panel" thing around the Settings.settings file (or any other settings file)?

有没有一种简单的方法可以在Settings.settings文件(或任何其他设置文件)中包装“首选项面板”?

Basically I have a bunch of strings stored in Settings.settings, and want to have a form where the user can edit these..

基本上我有一堆字符串存储在Settings.settings中,并希望有一个表单,用户可以编辑这些。

I could add a bunch of TextBoxes, and have a button that does Properties.blah = this.blahInput.Text; Properties.Save(); for each, but this feels like reinventing the wheel..

我可以添加一堆TextBoxes,并有一个按钮,它可以执行Properties.blah = this.blahInput.Text; Properties.Save();对于每一个,但这感觉像重新发明*..

Edit: The PropertyGrid control (as suggested by bassfriend's) seems perfect, but I cannot work out how to bind the property grid's SelectedObject to Properties.Settings.Default - When I try I get the following error:

编辑:PropertyGrid控件(由bassfriend的建议)似乎很完美,但我无法弄清楚如何将属性网格的SelectedObject绑定到Properties.Settings.Default - 当我尝试时,我得到以下错误:

Cannot implicitly convert type 'MyProject.Properties.Settings' to 'object[]'

3 个解决方案

#1


Maybe you want to take a look at the PropertyGrid Control.

也许你想看看PropertyGrid控件。

#2


I had no problem:

我没有问题:

        propertyGrid1.SelectedObject = Properties.Settings.Default;

I did have to change the visibility to Public in the Settings Designer.

我必须在Settings Designer中将可见性更改为Public。

#3


Maybe you need to use the Settings.Default.Properties property? That returns SettingsPropertyCollection which should be convertable to an object[].

也许你需要使用Settings.Default.Properties属性?返回SettingsPropertyCollection,它应该可以转换为object []。

#1


Maybe you want to take a look at the PropertyGrid Control.

也许你想看看PropertyGrid控件。

#2


I had no problem:

我没有问题:

        propertyGrid1.SelectedObject = Properties.Settings.Default;

I did have to change the visibility to Public in the Settings Designer.

我必须在Settings Designer中将可见性更改为Public。

#3


Maybe you need to use the Settings.Default.Properties property? That returns SettingsPropertyCollection which should be convertable to an object[].

也许你需要使用Settings.Default.Properties属性?返回SettingsPropertyCollection,它应该可以转换为object []。