自制控件属性问题,一定给分,可以看我以前提问的帖子
我想自己做个按钮控件,实现类似XP,或是OFFICE等按钮的效果。
我设定了几个属性:鼠标移动到按钮上时的颜色;鼠标按下时的颜色。等
问题是,我该怎么样把这几个属性指定到控件?
我试着将这几个属性都指定到控件的BACKCOLOR属性,但是在使用中只要改一个属性, 其他同时指定BACKCOLOR属性的自定义属性也同时改变。
如果能给个简单的例子说明,就更好了。
我的EMAIL:LIXIYO@163.COM
[解决办法]
自定义这些属性,不要map到usercontrol的属性上去,在paint过程中判断当前状态,比如是按下状态,则按照按下的颜色绘制。
[解决办法]
修改setProperty方法吧,看看代码就知道了
[解决办法]
控件代码,以 HoverColor 为例
Option Explicit
Private m_HoverColor As ColorConstants
Public Property Get HoverColor() As OLE_COLOR
HoverColor = m_HoverColor
End Property
Public Property Let HoverColor(ByVal RHS As OLE_COLOR)
m_HoverColor = RHS
PropertyChanged "HoverColor "
End Property
Private Sub UserControl_InitProperties()
m_HoverColor = vbGreen
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Me.HoverColor = PropBag.ReadProperty( "HoverColor ", vbGreen)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "HoverColor ", m_HoverColor, vbGreen
End Sub
[解决办法]
<System.ComponentModel.Category( "User "), System.ComponentModel.Description( "设置控件名称 ")> _
Public Property ControlName() As String
Get
Return lblName.Text
End Get
Set(ByVal Value As String)
lblName.Text = Value
End Set
End Property