创建一个属性网格的可扩展组? [英] Create an expandable group in a property grid?
问题描述
情景
块引用>
我已经子类一个
的ListBox
和我添加的,当我控制颜色属性的已启用 禁用或只读模式:
问题
块引用>
在C#或VB.Net,我需要做的组织在属性网格将扩展组,这种结构的特性:
[+]国家启用
〔+]所选项目
·背景色
·前景色
[+]未选中的项目
·背景色
·前景色
这是从
氪
lib中的用户控制采取的可视化示例演示什么我想模仿:
更新
块引用>
我认为,在这个网址进行了说明所有必要的财产左右网格:
的 http://www.codeproject.com/Articles/2764/Using-PropertyGrid-Part-I
但它的重点是与具有的加载活动的形式做到这一点,我仍然无法理解如何实现我的用户控件的例子,因为如果我创建一个子类自定义属性网格就像这个例子我就不能查看在我的控制的基础类
我的代码具有结构简单是这样的:
公共类ElektroListBox:继承列表框
<类别(外观)>
<描述(以下简称背景色绘制选定项目时,控制有效。)>
公共财产StateEnabledItemSelectedBackColor至于颜色
得到
返回Me.stateEnabledItemSelectedBackColor1
端获取
组(BYVAL值作为颜色)
Me.stateEnabledItemSelectedBackColor1 =价值
Me.Invalidate(invalidateChildren:= FALSE)
端设置
高端物业
私人stateEnabledItemSelectedBackColor1对于Color = Color.Red
端类
解决方案您需要做的第一件事就是组织你的属性成班。然后,你需要创建一个自定义每个类的类型转换器,使其成为序列化。但是,有一个更简单的方式来实现这一点;继承组件类。这里有一个简单的例子。
<预类=朗动prettyprint-覆盖>公共类UIListBox
继承列表框
酒店的公共子新()
Me.m_stateDisabled =新ItemLayout(我)
Me.m_stateEnabled =新ItemLayout(我)
Me.m_stateReadOnly =新ItemLayout(我)
端子
< DesignerSerializationVisibility(DesignerSerializationVisibility.Content)GT;
公共只读属性StateDisabled()作为ItemLayout
得到
返回Me.m_stateDisabled
端获取
高端物业
< DesignerSerializationVisibility(DesignerSerializationVisibility .Content)GT;
公共只读属性StateEnabled()作为ItemLayout
得到
返回Me.m_stateEnabled
端获取
高端物业
< DesignerSerializationVisibility(DesignerSerializationVisibility .Content)GT;
公共只读属性StateReadOnly()作为ItemLayout
得到
返回Me.m_stateReadOnly
端获取
高端物业
朋友分NotifyStateChanged(源作为ItemLayoutColors,propertyName的作为字符串)
Me.Invalidate()
的Debug.WriteLine(UIListBox:国家改变了。)
端子
私人m_stateDisabled作为ItemLayout
私人m_stateEnabled作为ItemLayout
私人m_stateReadOnly作为ItemLayout
端类
<的ToolboxItem(假)>
类公共ItemLayout
继承组件
的Public Sub New(列表框作为UIListBox)
Me.m_listBox =列表框
Me.m_background =新ItemLayoutColors(ME )
Me.m_foreground =新ItemLayoutColors(我)
端子
朋友只读属性列表框()作为UIListBox
得到
返回Me.m_listBox
端获取
高端物业
< DesignerSerializationVisibility(DesignerSerializationVisibility.Content)GT;
公共只读属性背景()作为ItemLayoutColors
得到
返回Me.m_background
端获取
高端物业
< DesignerSerializationVisibility(DesignerSerializationVisibility .Content)GT;
公共只读属性前景()作为ItemLayoutColors
得到
返回Me.m_foreground
端获取
高端物业
私人m_background作为ItemLayoutColors
私人m_foreground作为ItemLayoutColors
私人m_listBox作为UIListBox
端类
<的ToolboxItem(假)>
公共类ItemLayoutColors
继承组件
的Public Sub New(布局ItemLayout)
。如果(布局是没有什么)然后抛出新的ArgumentNullException(布局)
Me.m_layout =布局
端子
$ b)$ b朋友只读属性布局(如ItemLayout
得到
返回Me.m_layout
端获取
)选择(完房产
公共财产颜色
得到
返回Me.m_selected
端获取
套装(价值彩色)
。如果(价值<> Me.m_selected)然后
Me.m_selected =价值
Me.Layout.ListBox.NotifyStateChanged(ME,入选)
端如果
端设置
高端物业
$ b)$ b公共财产未选择(如颜色
得到
返回Me.m_unselected
端获取
套装(价值至于颜色)
。如果(价值<> Me.m_unselected)然后
Me.m_unselected =价值
Me.Layout.ListBox.NotifyStateChanged(Me中,未选中)
端如果
端设置
高端物业
专用功能ShouldSerializeSelected()为布尔
返回(Me.Selected<> Color.Empty)
端功能
专用功能ShouldSerializeUnselected( )为布尔
返回(Me.Unselected<> Color.Empty)
端功能
私人m_selected至于颜色
私人m_unselected至于颜色
私人m_layout作为ItemLayout
端类
设计文件
<预类=朗动prettyprint-覆盖>Me.UiListBox1.StateDisabled.Background.Selected = System.Drawing.Color.Red
SCENARIO
I've sub-classed a
ListBox
and I've added color properties for when my control is Enabled, Disabled, or in ReadOnly mode:
QUESTION
In C# or VB.Net, what I need to do to organize the properties in the property grid into expandable groups with this structure?:
[+] State Enabled [+] Selected Item · BackColor · ForeColor [+] Unselected Item · BackColor · ForeColor
This is a visual example taken from a
Krypton
lib user control that demonstrates what I would like to mimic:UPDATE
I think that in this url is explained all the necessary about property grids:
http://www.codeproject.com/Articles/2764/Using-PropertyGrid-Part-I
But it is focused to do it with form which has a Load event, I still can't understand how to implement that example in my user control because If I create a sub-class to customize the property grid like in that example then I can't acces to my control's base class.
My code has a simple structure like this:
Public Class ElektroListBox : Inherits ListBox <Category("Appearance")> <Description("The BackColor to paint the selected item when the control is enabled.")> Public Property StateEnabledItemSelectedBackColor As Color Get Return Me.stateEnabledItemSelectedBackColor1 End Get Set(ByVal value As Color) Me.stateEnabledItemSelectedBackColor1 = value Me.Invalidate(invalidateChildren:=False) End Set End Property Private stateEnabledItemSelectedBackColor1 As Color = Color.Red End Class
解决方案The first thing you need to do is to structure your properties into classes. Then you need to create a custom type converter for each class so it becomes serializable. However, there's an easier way to achieve this; inherit Component class. Here's a simple example.
Public Class UIListBox Inherits ListBox Public Sub New() Me.m_stateDisabled = New ItemLayout(Me) Me.m_stateEnabled = New ItemLayout(Me) Me.m_stateReadOnly = New ItemLayout(Me) End Sub <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> Public ReadOnly Property StateDisabled() As ItemLayout Get Return Me.m_stateDisabled End Get End Property <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> Public ReadOnly Property StateEnabled() As ItemLayout Get Return Me.m_stateEnabled End Get End Property <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> Public ReadOnly Property StateReadOnly() As ItemLayout Get Return Me.m_stateReadOnly End Get End Property Friend Sub NotifyStateChanged(source As ItemLayoutColors, propertyName As String) Me.Invalidate() Debug.WriteLine("UIListBox: State changed.") End Sub Private m_stateDisabled As ItemLayout Private m_stateEnabled As ItemLayout Private m_stateReadOnly As ItemLayout End Class <ToolboxItem(False)> Public Class ItemLayout Inherits Component Public Sub New(listBox As UIListBox) Me.m_listBox = listBox Me.m_background = New ItemLayoutColors(Me) Me.m_foreground = New ItemLayoutColors(Me) End Sub Friend ReadOnly Property ListBox() As UIListBox Get Return Me.m_listBox End Get End Property <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> Public ReadOnly Property Background() As ItemLayoutColors Get Return Me.m_background End Get End Property <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> Public ReadOnly Property Foreground() As ItemLayoutColors Get Return Me.m_foreground End Get End Property Private m_background As ItemLayoutColors Private m_foreground As ItemLayoutColors Private m_listBox As UIListBox End Class <ToolboxItem(False)> Public Class ItemLayoutColors Inherits Component Public Sub New(layout As ItemLayout) If (layout Is Nothing) Then Throw New ArgumentNullException("layout") Me.m_layout = layout End Sub Friend ReadOnly Property Layout() As ItemLayout Get Return Me.m_layout End Get End Property Public Property Selected() As Color Get Return Me.m_selected End Get Set(value As Color) If (value <> Me.m_selected) Then Me.m_selected = value Me.Layout.ListBox.NotifyStateChanged(Me, "Selected") End If End Set End Property Public Property Unselected() As Color Get Return Me.m_unselected End Get Set(value As Color) If (value <> Me.m_unselected) Then Me.m_unselected = value Me.Layout.ListBox.NotifyStateChanged(Me, "Unselected") End If End Set End Property Private Function ShouldSerializeSelected() As Boolean Return (Me.Selected <> Color.Empty) End Function Private Function ShouldSerializeUnselected() As Boolean Return (Me.Unselected <> Color.Empty) End Function Private m_selected As Color Private m_unselected As Color Private m_layout As ItemLayout End Class
Designer file
Me.UiListBox1.StateDisabled.Background.Selected = System.Drawing.Color.Red
这篇关于创建一个属性网格的可扩展组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!