怎么自定义ProgressBar的颜色

2024-11-25 14:56:54
推荐回答(1个)
回答1:

给你举个例子,是改进度条颜色滴,自己延伸下吧~

Option Explicit

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 Const WM_USER = &H400
Private Const PBM_SETBARCOLOR = (WM_USER + 9)

Private Function SetProgressBarColor(TargetProgressBar As ProgressBar) '进度条的颜色

SendMessage TargetProgressBar.hwnd, PBM_SETBARCOLOR, 0, ByVal RGB(IIf(TargetProgressBar.Value / TargetProgressBar.Max * 255 < 255 * 0.5, TargetProgressBar.Value / TargetProgressBar.Max * 255 * 2, 255), IIf(TargetProgressBar.Value / TargetProgressBar.Max * 255 < 255 * 0.5, 255, (255 - TargetProgressBar.Value / TargetProgressBar.Max * 255) * 2), 0)

End Function

Private Sub Command1_Click()

If ProgressBar1.Value < ProgressBar1.Max Then
ProgressBar1.Value = ProgressBar1.Value + 10
Else
ProgressBar1.Value = 0
End If

SetProgressBarColor ProgressBar1

End Sub

Private Sub Form_Load()

ProgressBar1.Max = 100
ProgressBar1.Value = 0

End Sub

'自己添加控件试下吧