VB自带的command控件不支持文字变色,只有默认黑色。
你可以使用一个label标签代替command,这样就行了。label也支持Click、mousemove等事件,只是没有command的立体感强。
代码是跟右下角的属性一样的。属性是什么名称,你代码就写什么名称,属性值有什么,你就填什么。
Private Declare Function SetSysColors Lib "user32 " (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
Private Declare Function GetSysColor Lib "user32 " (ByVal nIndex As Long) As Long
Dim OriginalColor As Long
Dim NewColor As Long
Private Const COLOR_BTNTEXT = 18
Private Sub Command1_Click()
If NewColor = vbRed Then NewColor = OriginalColor Else NewColor = vbRed
SetSysColors 1, COLOR_BTNTEXT, NewColor
End Sub
Private Sub Form_Load()
OriginalColor = GetSysColor(COLOR_BTNTEXT)
End Sub
Private Sub Form_Unload(Cancel As Integer)
NewColor = OriginalColor
SetSysColors 1, COLOR_BTNTEXT, NewColor
End Sub