摘要
CollectionEditor 是最基本的集合属性编辑器,如 ListBox 的 Items 属性编辑器(ListItemsCollectionEditor)即为继承 CollectionEditor 而来。如图1所示,为 ListBox 的 Items 属性编辑器,编辑窗口右边的属性窗口预设是没有显示 [说明] 区域的。如果我们要让它如图2所示的 GridView 的 Columns 属性编辑器,在属性窗口下方一样具有 [说明] 区域,要如何处理呢?本文将以 ListBox 的 Items 属性编辑器为例,说明如何让 CollectionEditor 的属性窗口一样可以显示 [说明] 区域。
CollectionEditor 显示 [说明] 区域
图1. ListBox 的 Items 属性编辑器
CollectionEditor 显示 [说明] 区域
图2. GridView 的 Columns 属性编辑器

改写集合属性编辑器
我们要改写 ListBox 的 Items 属性编辑器,故继承 ListItemsCollectionEditor 下来命名为 TBListItemsCollectionEditor。主要作法是覆写 CreateCollectionForm 方法,找到编辑窗口中的属性编辑器控件(System.Windows.Forms.PropertyGrid),并设定 PropertyGrid.HelpVisible = True 即可。
 1CollectionEditor 显示 [说明] 区域Imports System.Drawing.Design
 2CollectionEditor 显示 [说明] 区域Imports System.Windows.Forms.Design
 3CollectionEditor 显示 [说明] 区域Imports System.ComponentModel
 4CollectionEditor 显示 [说明] 区域Imports System.ComponentModel.Design
 5CollectionEditor 显示 [说明] 区域Imports System.Reflection
 6CollectionEditor 显示 [说明] 区域Imports System.Web.UI.Design.WebControls
 7CollectionEditor 显示 [说明] 区域
 8End Namespace

套用 TBListItemsCollectionEditor 属性编辑器
首先继承 ListBox 下来命名为 TBListBox,再覆写 Items 属性,使用 Editor 重新定义该属性编辑器为 TBListItemsCollectionEditor。
 1CollectionEditor 显示 [说明] 区域Imports System
 2CollectionEditor 显示 [说明] 区域Imports System.Collections.Generic
 3CollectionEditor 显示 [说明] 区域Imports System.ComponentModel
 4CollectionEditor 显示 [说明] 区域Imports System.Text
 5CollectionEditor 显示 [说明] 区域Imports System.Web
 6CollectionEditor 显示 [说明] 区域Imports System.Web.UI
 7CollectionEditor 显示 [说明] 区域Imports System.Web.UI.WebControls
 8CollectionEditor 显示 [说明] 区域Imports Bee.Web.WebControls.Design
 9CollectionEditor 显示 [说明] 区域
10End Namespace

测试结果
在页面上放置设计完成的 TBListBox 控件,在属性窗口中编辑 Items 属性,就可以看到我们重新定义的 TBListItemsCollectionEditor 编辑器出现 [说明] 区域。

CollectionEditor 显示 [说明] 区域

CollectionEditor 显示 [说明] 区域



 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2021-12-04
  • 2021-06-20
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-30
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-11-08
  • 2021-09-29
  • 2021-08-19
相关资源
相似解决方案