0

我有很多路径可以在我的项目中使用。当您使用 Appication Settings 时,您可以将 Settings 对象PropertyGrid与代码一起提供给 a:PropertyGrid1.SelectedObject = My.Settings()

我读到你可以提供一个对象(在这种情况下是一个自定义对象,而不是My.Settings这个信息:

<Editor(GetType(System.Windows.Forms.Design.FileNameEditor), _
        GetType(System.Drawing.Design.UITypeEditor))>

为了应用打开文件浏览器的编辑器,当您使用PropertyGrid. 那太好了,而且有效。

是否有可能在 VS2010 UI 中执行此类操作以与应用程序设置一起使用?

我的意思是,我意识到将属性的类型设置为System.Windows.Forms.Design.FileNameEditor将设置其类型而不是其编辑器,这很简单。我也尝试设置System.Windows.Forms.Design.FileNameEditor为该属性的提供者,但没有运气。

我已经打开了文件Settings.Designer.vb,我已经手动添加了这一行:

<Editor(GetType(System.Windows.Forms.Design.FileNameEditor), _
        GetType(System.Drawing.Design.UITypeEditor))>

到我想显示文件选择器和工作的属性。问题是文件是自动生成的,不应该被编辑。

如何使用 Visual Studio 2010 的适当过程重复该行为?

4

1 回答 1

1

Just read the application settings into your own class and assign that class to the propertygrid. I took this edited somewhat from one of my projects:

Call MyFilenameClass
 <Editor(GetType(System.Windows.Forms.Design.FileNameEditor), GetType(System.Drawing.Design.UITypeEditor)), _
  Browsable(True), _
  DefaultValue(""), _
  Category("File"), DisplayName("Filename"), Description("Select the file.")> _
  Public Property MyFileName As String = My.Settings.MyFilename
End Class

So, when the class is created, MyFilename will have the value of My.Settings.MyFilename. In your Form_Closing you will need to put your value back into the Application setting and save it:

My.Settings.MyFilename = "class name in here".MyFilename
My.Settings.Save
于 2012-09-13T12:29:48.353 回答