如何在自定义控件内加入属性组?
我所谓的“属性组”是好像Font属性这样,里面还有属性,比如Bold,可以设置的假设有一个class,为TestClass,而我要做到有这样的属性:
|-CustomGradientPanel
|-->Color1
|-->Color2
代码又应该怎么打呢?
如果只是“单级”的属性,我就会:
--------------------编程问答--------------------
Class TestClass
Dim myColor1, myColor2 as color
Public Property Color1 as Color
Get
Return myColor1
End Get
Set(ByVal value As Color)
myColor1 = value
End Set
End Property
Public Property Color2 as Color
Get
Return myColor2
End Get
Set(ByVal value As Color)
myColor2 = value
End Set
End Property
End Class
Class TestClass--------------------编程问答--------------------
Dim myColor _myColor
Public Property MyColor as myColor
Get
Return _myColor
End Get
Set(ByVal value As myColor)
_myColor= value
End Set
End Property
End Class
public class myColor
Dim myColor1, myColor2 as color
Public Property Color1 as Color
Get
Return myColor1
End Get
Set(ByVal value As Color)
myColor1 = value
End Set
End Property
Public Property Color2 as Color
Get
Return myColor2
End Get
Set(ByVal value As Color)
myColor2 = value
End Set
End Property
end class
貌似不行啊……
--------------------编程问答-------------------- Dim myColor _myColor
把上面这句改成
Dim _myColor as new myColor --------------------编程问答--------------------
试过了,也是一样…… --------------------编程问答-------------------- 你刚才用集合吧
这个代码测试,在属性里可以添加颜色集合
Private _myColor As New List(Of Color)()--------------------编程问答--------------------
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property myColor() As List(Of Color)
Get
Return _myColor
End Get
Set
_myColor = value
End Set
End Property
谢谢了~ 我找到解决方法了~
原来是我忘记加"<TypeConverter(GetType(ExpandableObjectConverter))> _"在class前面了
现在的代码如下:
--------------------编程问答--------------------
Imports System.ComponentModel
Class TestClass
Inherits Button
Dim _myColor As New myColor
Public Property MyColor As myColor
Get
Return _myColor
End Get
Set(ByVal value As myColor)
_myColor = value
End Set
End Property
End Class
<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class myColor
Dim myColor1, myColor2 As Color
Public Property Color1 As Color
Get
Return myColor1
End Get
Set(ByVal value As Color)
myColor1 = value
End Set
End Property
Public Property Color2 As Color
Get
Return myColor2
End Get
Set(ByVal value As Color)
myColor2 = value
End Set
End Property
End Class
补充:.NET技术 , VB.NET