网上找到的一段代码,某个高人写的,太牛逼了。貌似是百度贴吧VB6,精巧犀利。。。。。
https://tieba.baidu.com/p/4731580018
VB6这么老旧的语言平台,不要以为很垃圾,有时候写精巧小代码还是一个很顺手的得力工具。
回归正题,直接用一个原生PictiureBox控件生成自定义进度条,不再依赖外部MSCOMCTL.OCX控件。不但能模拟彩色进度条,还支持字符反显!!!
Public Sub SetProgress(PBar As PictureBox, ByVal Value As Long, ByVal Max As Long, Optional ByVal Describe As String = "")
Dim showText As String
Dim drawLength As Long
drawLength = (Value * PBar.ScaleWidth / Max)
If Describe = "" Then
showText = Format(Value * 100 / Max, "#0.00") & "%" '改小数点
Else
showText = Describe
End If
With PBar
.AutoRedraw = True
.Cls
.CurrentX = (.ScaleWidth - .TextWidth(showText)) / 2
.CurrentY = (.ScaleHeight - .TextHeight(showText)) / 2
.FontBold = True
PBar.Print showText .DrawMode = 8
PBar.Line (0, 0)-(drawLength, .ScaleHeight), Not RGB(51, 153, 255), BF '改背景色
.AutoRedraw = False
.Refresh
End With
End Sub