如何实现VB的命令按钮command1单击后按钮上的文字变成红色,再单击变成默认的颜色?

我一定也不懂,你能给我做一个样子看看么我这着急需要谢谢
2024-12-29 12:11:55
推荐回答(3个)
回答1:

VB自带的command控件不支持文字变色,只有默认黑色。
你可以使用一个label标签代替command,这样就行了。label也支持Click、mousemove等事件,只是没有command的立体感强。

回答2:

代码是跟右下角的属性一样的。属性是什么名称,你代码就写什么名称,属性值有什么,你就填什么。

回答3:

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