VB中用一个按钮来控制一个shape,当按钮按下一次时shape显示一种颜色,按钮再按一次时就显示另一种颜色?
展开全部
抛砖引玉
Private Sub Command1_Click()
If Shape1.FillColor = vbBlack Then
Shape1.FillColor = vbRed
Shape1.BorderColor = vbRed
ElseIf Shape1.FillColor = vbRed Then
Shape1.FillColor = vbBlue
Shape1.BorderColor = vbBlue
ElseIf Shape1.FillColor = vbBlue Then
Shape1.FillColor = vbGreen
Shape1.BorderColor = vbGreen
ElseIf Shape1.FillColor = vbGreen Then
Shape1.FillColor = vbYellow
Shape1.BorderColor = vbYellow
ElseIf Shape1.FillColor = vbYellow Then
Shape1.FillColor = vbWhite
Shape1.BorderColor = vbWhite
ElseIf Shape1.FillColor = vbWhite Then
Shape1.FillColor = vbMagenta
Shape1.BorderColor = vbMagenta
ElseIf Shape1.FillColor = vbMagenta Then
Shape1.FillColor = vbCyan
Shape1.BorderColor = vbCyan
ElseIf Shape1.FillColor = vbCyan Then
'随机颜色
Dim r As Integer, g As Integer, b As Integer
r = CInt(Rnd * (255 - 0 + 1)) + 0
g = CInt(Rnd * (255 - 0 + 1)) + 0
b = CInt(Rnd * (255 - 0 + 1)) + 0
Shape1.FillColor = RGB(r, g, b)
Shape1.BorderColor = RGB(r, g, b)
Else
Shape1.FillColor = vbBlack
Shape1.BorderColor = vbBlack
End If
End Sub
Private Sub Command1_Click()
If Shape1.FillColor = vbBlack Then
Shape1.FillColor = vbRed
Shape1.BorderColor = vbRed
ElseIf Shape1.FillColor = vbRed Then
Shape1.FillColor = vbBlue
Shape1.BorderColor = vbBlue
ElseIf Shape1.FillColor = vbBlue Then
Shape1.FillColor = vbGreen
Shape1.BorderColor = vbGreen
ElseIf Shape1.FillColor = vbGreen Then
Shape1.FillColor = vbYellow
Shape1.BorderColor = vbYellow
ElseIf Shape1.FillColor = vbYellow Then
Shape1.FillColor = vbWhite
Shape1.BorderColor = vbWhite
ElseIf Shape1.FillColor = vbWhite Then
Shape1.FillColor = vbMagenta
Shape1.BorderColor = vbMagenta
ElseIf Shape1.FillColor = vbMagenta Then
Shape1.FillColor = vbCyan
Shape1.BorderColor = vbCyan
ElseIf Shape1.FillColor = vbCyan Then
'随机颜色
Dim r As Integer, g As Integer, b As Integer
r = CInt(Rnd * (255 - 0 + 1)) + 0
g = CInt(Rnd * (255 - 0 + 1)) + 0
b = CInt(Rnd * (255 - 0 + 1)) + 0
Shape1.FillColor = RGB(r, g, b)
Shape1.BorderColor = RGB(r, g, b)
Else
Shape1.FillColor = vbBlack
Shape1.BorderColor = vbBlack
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询