VB and VBA Users Source Code: Create a progress bar from a PictureBox
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Create a progress bar from a PictureBox
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, June 20, 2001
Hits:
778
Category:
Windows Forms/GUI/Controls/Graphics
Article:
The following code demonstrates a simple technique for turning a VB PictureBox into a progress bar. 'Purpose : Creates a progress bar from a picture box 'Inputs : pbProgress The picture box. ' lPercentComplete The percentage complete of the progress bar. ' [lBackColor] The backcolor of the progress bar (default uses system backcolor). ' [lForeColor] The forecolor of the progress bar (default uses blue). 'Outputs : Returns 0 on success, else returns an error code 'Author : Andrew Baker 'Date : 25/03/2001 'Notes : Example usuage: ' DrawProgressBar Picture1, 10 'Draws the progress bar 10% complete Function DrawProgressBar(pbProgress As PictureBox, lPercentComplete As Long, Optional lBackColor As OLE_COLOR = &H8000000F, Optional lForeColor As OLE_COLOR = vbBlue) As Long Dim fPercent As Single Dim lLenBar As Integer On Error GoTo ErrFailed fPercent = lPercentComplete / 100 lLenBar = fPercent * pbProgress.ScaleWidth 'Fill both sides of the bar (incase a backwards progress bar is required) pbProgress.AutoRedraw = True pbProgress.BackColor = lBackColor pbProgress.ForeColor = lForeColor pbProgress.Line (0, 0)-(lLenBar, pbProgress.Height), pbProgress.ForeColor, BF pbProgress.Line (lLenBar + 1, 0)-(pbProgress.ScaleWidth, pbProgress.Height), pbProgress.BackColor, BF DrawProgressBar = 0 Exit Function ErrFailed: Debug.Print "Error in DrawProgressBar: " & Err.Description Debug.Assert False DrawProgressBar = Err.Number End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder