1. 程式人生 > >VB6的一個奇技淫巧

VB6的一個奇技淫巧

網上找到的一段程式碼,某個高人寫的,太牛逼了。貌似是百度貼吧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



效果: