
08-24-2005, 09:12 PM
|
 |
Senior Contributor
|
|
Join Date: Mar 2003
Location: The 19th Hole
Posts: 989
|
|
Alternative To Progressbar
|
I'm using a picturebox as an alternative to a progressbar however when I update it it's not smooth like a progressbar. Is this just the way the picturebox works or can I "smooth" the updating?
Below is the code I'm using.
Code:
Option Explicit
Dim f As PictureBox
Dim i As Long
Private Sub Form_Load()
Me.Show
Set f = tbFlood
'initialize the control by setting:
'white (the text colour)
'black (the flood panel colour)
'not Xor pen
'solid fill
f.Cls
f.BackColor = &HFFFFFF
f.ForeColor = &H800000
f.DrawMode = 10
f.FillStyle = 0
f.ScaleWidth = 1000 'upperLimit
f.Cls
f.Visible = True
For i = 0 To 10000
UpdateProgress 1000, i
Next
End Sub
Public Sub UpdateProgress(upperLimit As Double, progress As Long)
Dim sProgressMessage As String
sProgressMessage = "Importing Details...."
Dim pc As String
If progress <= upperLimit Then
If progress > tbFlood.ScaleWidth Then progress = tbFlood.ScaleWidth
tbFlood.Cls
tbFlood.ScaleWidth = upperLimit
'format the progress into a percentage string to display
pc = Format$(CLng((progress / tbFlood.ScaleWidth) * 100)) + "%"
DoEvents
'calculate the string's X & Y coordinates
'in the PictureBox ... here, left justified and offset slightly
tbFlood.CurrentX = 2
tbFlood.CurrentY = (tbFlood.ScaleHeight - tbFlood.TextHeight(sProgressMessage)) \ 2
'print the percentage string in the text colour
DoEvents
tbFlood.Print sProgressMessage & " " & pc
'print the flood bar to the new progress length in the line colour
tbFlood.Line (0, 0)-(progress, tbFlood.ScaleHeight), tbFlood.ForeColor, BF
'without this Refresh, the progress won't update
tbFlood.Refresh
End If
End Sub
|
|