我自己找了一下,这样会更简单。
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Command1_Click()
ProgressBar1.Value = 55
SendMessage ProgressBar1.hwnd, &H2001, 0&, ByVal vbGreen
SendMessage ProgressBar1.hwnd, &H409, 0&, ByVal vbWhite
End Sub
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
Static x As Long
Static direction As Boolean
If direction = False Then
Picture1.ForeColor = RGB((255 / Picture1.Width) * x, 0, 255)
x = x + 5
Picture1.Line (x, 0)-(x, Picture1.Height)
If x >= Picture1.Width Then direction = True
Else
Picture1.ForeColor = RGB((255 / Picture1.Width) * x, 255, 0)
x = x - 5
Picture1.Line (x, 0)-(x, Picture1.Height)
If x <= 0 Then direction = False
End If
End Sub