我定义了一个自定义按钮类,当按钮启用/禁用时设置背景颜色。
运行时的启用外观(A):
运行时的禁用外观(B):
设计时外观始终是(A),无论 Enabled
属性的值如何。
我希望我的控件在设计器中显示的方式与运行时完全一样。这可能吗?如果可以,怎么做?
这是我尝试过的(只包括相关代码的部分):
Public Class StyledButton : Inherits Button
Private p_fEnabled As Boolean
<DefaultValue(True)>
Public Shadows Property Enabled As Boolean
Get
Return p_fEnabled
End Get
Set(value As Boolean)
p_fEnabled = value
MyBase.Enabled = value
UpdateVisualStyle()
End Set
End Property
Private Sub UpdateVisualStyle()
If Me.Enabled Then
'set enabled appearance
Else
'set disabled appearance
End If
End Sub
End Class
UpdateVisualStyle
的末尾调用Me.Invalidate()
,还尝试了Me.Refresh()
。但是,在设计时没有改变行为。还有其他想法吗? - Victor ZakharovneoEnabled
,它就可以工作了(使用Invalidate)。 - Ňɏssa Pøngjǣrdenlarp