CollectionEditor 显示 [说明] 区域

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

图1. ListBox 的 Items 属性编辑器

图2. GridView 的 Columns 属性编辑器

改写集合属性编辑器
我们要改写 ListBox 的 Items 属性编辑器,故继承 ListItemsCollectionEditor 下来命名为 TBListItemsCollectionEditor。主要作法是覆写 CreateCollectionForm 方法,找到编辑窗口中的属性编辑器控件(System.Windows.Forms.PropertyGrid),并设定 PropertyGrid.HelpVisible = True 即可。
 1 Imports  System.Drawing.Design
 2 Imports  System.Windows.Forms.Design
 3 Imports  System.ComponentModel
 4 Imports  System.ComponentModel.Design
 5 Imports  System.Reflection
 6 Imports  System.Web.UI.Design.WebControls
 7
 8 Namespace WebControls Namespace WebControls.Design
 9    Public Class TBListItemsCollectionEditorClass TBListItemsCollectionEditor
10        Inherits ListItemsCollectionEditor
11
12        Public Sub New()Sub New(ByVal newType As Type)
13            MyBase.new(newType)
14        End Sub

15
16        /**/''' <summary>
17        ''' 覆写。建立集合属性编辑器窗体。
18        ''' </summary>

19        Protected Overrides Function CreateCollectionForm()Function CreateCollectionForm() As System.ComponentModel.Design.CollectionEditor.CollectionForm
20            Dim oForm As CollectionEditor.CollectionForm
21            Dim oType As Type
22            Dim oFieldInfo As FieldInfo
23            Dim oPropertyGrid As System.Windows.Forms.PropertyGrid
24
25            oForm = MyBase.CreateCollectionForm()
26            oType = oForm.GetType()
27            oFieldInfo = oType.GetField("propertyBrowser", BindingFlags.NonPublic Or BindingFlags.Instance)
28            If oFieldInfo IsNot Nothing Then
29                '取得属性窗口控件
30                oPropertyGrid = CType(oFieldInfo.GetValue(oForm), System.Windows.Forms.PropertyGrid)
31                '设定属性窗口控件的[说明]区域为可视
32                oPropertyGrid.HelpVisible = True
33            End If
34            Return oForm
35        End Function

36
37    End Class

38End Namespace

套用 TBListItemsCollectionEditor 属性编辑器
首先继承 ListBox 下来命名为 TBListBox,再覆写 Items 属性,使用 Editor 重新定义该属性编辑器为 TBListItemsCollectionEditor。
 1 Imports  System
 2 Imports  System.Collections.Generic
 3 Imports  System.ComponentModel
 4 Imports  System.Text
 5 Imports  System.Web
 6 Imports  System.Web.UI
 7 Imports  System.Web.UI.WebControls
 8 Imports  Bee.Web.WebControls.Design
 9
10 Namespace WebControls Namespace WebControls
11    < _
12    Description("清单控件"), _
13    ToolboxData("<{0}:TBListBox runat=server></{0}:TBListBox>") _
14    > _
15    Public Class TBListBoxClass TBListBox
16        Inherits ListBox
17
18        <Editor(GetType(TBListItemsCollectionEditor), GetType(System.Drawing.Design.UITypeEditor))> _
19        Public Overrides ReadOnly Property Items()Property Items() As ListItemCollection
20            Get
21                Return MyBase.Items
22            End Get
23        End Property

24
25    End Class

26End Namespace

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






 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值