VB菜菜鸟问题 !菜鸟,高手请进

Private Sub Command1_Click()Text1.BackColor = vbRedEnd Sub第二次单击变成绿色
2024-12-27 06:59:57
推荐回答(1个)
回答1:

'判断 Text1 当前颜色,然后赋值
Private Sub Command1_Click()
If Text1.BackColor = vbRed then
Text1.BackColor = vbGreen
Else
Text1.BackColor = vbRed
End If
End Sub

'或者也可以这样写,意思一样
Private Sub Command1_Click()
Text1.BackColor = IIf( Text1.BackColor = vbRed , vbGreen , vbRed )
End Sub