Private Sub WriteToProgressBar(ByVal pbIn As ProgressBar, ByVal sTextToDraw As String, ByVal f As Font, ByVal b As Brush)
Using g As Graphics = Me.CreateGraphics
'Check to see if text is to wide/tall
If sTextToDraw.Length * f.Size > pbIn.Width Or _
f.Height > pbIn.Height Then
Throw New ArgumentException("Text is to large for progress bar!")
Dim iTryGetCenterW As Integer = (pbIn.Width / 2) - ((sTextToDraw.Length * f.Size) / 2)
Dim iTryGetCenterH As Integer = (pbIn.Height / 2) - (f.Size / 2)
g.DrawString(sTextToDraw, f, b, New Point(iTryGetCenterW, iTryGetCenterH))
Catch ex As Exception
You will have to take the progress bar's location into consideration as well.
But you must take the progress bar's location into consideration.
It's going to be a problem because every time you call g.DrawString it will write overtop of the existing text as the numbers change you will end up with just a black blob. Previously rendered numbers will not be erased. You can find a custom progress bar at Code Project which might do what you want.
Hi had the same problem with the ProgressBar is pretty complicated, so I ended up creating my own BAR.
I used a Label as bar, because I can give it the size I want, put tekst in it, and give it the Back- and ForeColor I want. Also a Timer to Make events happen. As it is it counts Up to any number of seconds, with a
few changes in the code it will count Down from any number of seconds. Have not tried it but must be possible to use with bytes or so as well. The code below is what I wrote for testing my BAR. Maybe it helps you.
Public Class Form1
Dim counttill As Integer = 180 ' change to any value for seconds to count
Dim barwidth As Integer = 500 ' change to any value for maximum width of Label1
Dim barsize As Double = 0
Dim nextpixel As Double = 0
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
nextpixel = (barwidth / counttill).ToString 'calculate number of pixels to add with each step
Label1.Width = 0
Timer1.Interval = 1000
Timer1.Enabled = True
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
counttill += 1
barsize = barsize + nextpixel
Label1.Width = barsize
Dim prcnt As Integer = barwidth / 100 ' where prcnt is 1% of maximum barwidth
Dim percent As Integer = barsize / prcnt ' actual barwidth in %
Label1.Text = percent & "%"
Label2.Text = barsize ' not needed is just for checking
If percent = 100 Then
Timer1.Enabled = False
Tried it another way, used the ProgressBar to make a Label scroll like it, works ok for me.
Works with a Trackbar as well. I added this code to a ProgressBar routine. Where xxx = maximum width for label1, used same size as for ProgressBar. Percentage can be put in like shown before.
public class GrossmontBank
//class variables (global - accessible throughout this class)
//scanner object to be used throughout
private static Scanner input = new Scanner(System.in);