VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Percent Bar Transforms a PictureBox into a Percent Bar

by _andy_ (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

I thought this code might help those struggling to make a percent bar. This code transforms a normal picturebox into a Percent Bar (progress bar with % in the middle). Choose from 2 different borders.

Inputs
pic As PictureBox, ByVal Percent As Integer, Optional ByVal Flat As Boolean = False

Rate Percent Bar Transforms a PictureBox into a Percent Bar

Public Sub UpdateProgress(pic As PictureBox, ByVal Percent As Single, Optional ByVal Flat As Boolean = False)
 With pic
 'Configure PictureBox
 .AutoRedraw = True
 .Appearance = Flat + 1
 .ScaleWidth = 100
 .ForeColor = vbHighlight
 .BackColor = vbButtonFace
 .DrawMode = vbNotXorPen
 
 'Clear the PictureBox
 .Cls
 
 'Draw the text
 .CurrentX = (.ScaleWidth - .TextWidth(Int(Percent) & "%")) \ 2
 .CurrentY = (.ScaleHeight - .TextHeight(Int(Percent) & "%")) \ 2
 pic.Print Int(Percent) & "%"
 
 'Draw the progress
 pic.Line (0, 0)-(Percent, .ScaleHeight), , BF
 End With
End Sub

Download this snippet    Add to My Saved Code

Percent Bar Transforms a PictureBox into a Percent Bar Comments

No comments have been posted about Percent Bar Transforms a PictureBox into a Percent Bar. Why not be the first to post a comment about Percent Bar Transforms a PictureBox into a Percent Bar.

Post your comment

Subject:
Message:
0/1000 characters