Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Forms Code Examples

Create a progress bar from a PictureBox

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Create a progress bar from a PictureBox 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 '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