65.9K
CodeProject 正在变化。 阅读更多。
Home

使用自定义类型编辑器随心所欲地操控 .NET PropertyGrid

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.41/5 (14投票s)

2004年1月13日

viewsIcon

119537

downloadIcon

951

VB.NET 中使用 Tony Allowatt 的 propertybag 类和自定义类型编辑器的示例

Sample Image - Propertygrid_Editor_demo.jpg

引言

我在做这两件事时遇到了严重的问题

  • 在 VB.NET 中使用 PropertyGrid,并使其所有属性(例如属性名称和显示的描述)都是动态的
  • 将 Tony Allowat 的类(解决了第一个问题)与自定义类型编辑器一起使用

我终于成功地让它工作了……我想你们中的其他人可能也遇到了同样的问题。所以,这就是我的 VB.NET 版本,它使用了 Tony Allowatt 的 propertybag 类,并实现了一个自定义类型编辑器。

背景

PropertyBag.vb 文件的代码不是我写的……Tony Allowatt 为 propertygrid 编写了这些有用的类,但使用的是 C#。请先阅读他的文章! Bending the .NET PropertyGrid to Your Will

使用代码

我不会在这里详细解释太多,因为 Tony Allowatt 已经在他的文章中解释了所有重要的代码。我只是提供一个如何将他的类与自定义编辑器一起使用的示例。

Public Class MyOwnClass
 ' the class that will be shown in the propertygrid
 ' it has a property of typ MultiLineString
End Class 

Public Class MultiLineString
 ' this is the custom type we'll want to edit in the propertygrid
 ' it's just a class with 1 property, a string, but 
 ' we want a multiline editor for it

 ' ...
End Class

Public Class MultiLineStringEditor
 Inherits UITypeEditor
 ' ...
End Class

Public Class MultiLineStringConverter
 Inherits System.ComponentModel.TypeConverter
 ' ...
End Class

Public Class MultiLineStringEditorForm
 Inherits System.Windows.Forms.Form
 ' ...
End Class

关注点

一些有趣的链接

历史

  • 2004-01-14 - 初始发布
© . All rights reserved.