集团在自定义的控件属性 [英] Group properties in a custom control
问题描述
在我们的IDE,比如,Visual Studio中,如果我们显示System.Windows.Forms.Button控件的属性,我们可以看到一些属性,揭露anoter的属性集。例如: FlatAppearance,字体,位置,保证金的,等等
In our IDE, for example, Visual Studio, if we display the properties of a System.Windows.Forms.Button control, we see some properties that expose anoter set of properties. For example: FlatAppearance, Font, Location, Margin, etcetera.
我希望做一个自定义的控制类似的东西。
I would like to do something similar in a custom control.
我知道code的背后是错误,但这里是什么I'm试图做一个例子:
I know the code behind is wrong, but here is an example of what I´m trying to do:
Public Class StateOfMyCustomControl
Public Enum EnumVisibility
Visible
NonVisible
End Enum
Public Enum EnumEventManagement
Automatic
Manual
End Enum
Private mAssociatedControl As MyCustomControl
Private mVisibility As EnumVisibility
Private mEventManagement As EnumEventManagement
Public Sub New(ByVal AssociatedControl As MyCustomControl)
mAssociatedControl = AssociatedControl
End Sub
Public Property Visibility() As EnumVisibility
Get
Return mVisibility
End Get
Set(ByVal value As EnumVisibility)
mVisibility = value
mAssociatedControl.Visible = False
If mVisibility = EnumVisibility.Visible Then
mAssociatedControl.Visible = True
End If
End Set
End Property
Public Property EventManagement() As EnumEventManagement
Get
Return mEventManagement
End Get
Set(ByVal value As EnumEventManagement)
mEventManagement = value
End Set
End Property
End Class
Public Class MyCustomControl
' ...
Private mState As StateOfMyCustomControl
Public Sub New()
mState = New StateOfMyCustomControl(Me)
End Sub
Public Property State() As StateOfMyCustomControl
Get
Return mState
End Get
Set(ByVal value As StateOfMyCustomControl)
mState = value
End Set
End Property
' ...
End Class
在我的IDE,在我的自定义控件的属性窗口,我想看看我的财产的国家的,以显示它的可能性来设置属性的能见度的和 EventManagement 的。
In my IDE, in the properties window of my custom control, I would like to see my property State, with the possibility of display it to set the properties Visibility and EventManagement.
非常感谢
推荐答案
您需要告诉它使用 ExpandableObjectConverter
(或自定义转换器)的 StateOfMyCustomControl
。在C#中,这就是:
You need to tell it to use ExpandableObjectConverter
(or a custom converter) for StateOfMyCustomControl
. In C#, this is:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class StateOfMyCustomControl {...}
不过你申请的属性在VB中,做到这一点;-p
However you apply attributes in VB, do that ;-p
可能:
<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class StateOfMyCustomControl
...
这篇关于集团在自定义的控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!