Zharphyn
asked on
Placing a label on a Progress Bar
I am writing a windows program, and on one form, I have a progress bar. I found some code to write a label over the progress bar to indicate percentage, and the code works, when percentage is 0%. Once the progress bar value is greater than 0, the progress bar has an animation that runs every second. This animation causes my label to be hidden.
My question is:
What is the easiest way to have a label appear on a progress bar in VB.NET? Or can I turn off the animation?
Thanks
Brad
Private Sub SetProgressBarText()
Dim szPercent As String
Dim szTextString As String
szPercent = CInt(((pbrTimeRemaining.Value - pbrTimeRemaining.Minimum) / (pbrTimeRemaining.Maximum - pbrTimeRemaining.Minimum)) * 100).ToString & "%"
szTextString = "Training Time Used - " & szPercent
Dim g As Graphics = pbrTimeRemaining.CreateGraphics()
g.DrawString(szTextString, SystemFonts.DefaultFont, Brushes.Black, _
New PointF(pbrTimeRemaining.Width / 2 - (g.MeasureString(szTextString, SystemFonts.DefaultFont).Width / 2), _
pbrTimeRemaining.Height / 2 - (g.MeasureString(szTextString, SystemFonts.DefaultFont).Height / 2)))
pbrTimeRemaining.Refresh()
End Sub
My question is:
What is the easiest way to have a label appear on a progress bar in VB.NET? Or can I turn off the animation?
Thanks
Brad
ASKER
I am already doing that. What appears to be happening, is that every second, the progress bar has an animation occur, and this animation either removes or hides the text. Is there a way to turn off this animation, or to have the animation also update the text?
Thanks
Brad
Thanks
Brad
The animation might come from the fact that you have set the Style property to Marquee. In Marquee mode, there is no way to intervene, because for some reason, the ProgressBar does not trigger a Paint event as most controls do.
Check the Style, and set it to something else than Marquee if this is set.
Also, be sure to call your method after the value has been changed, not before.
Check the Style, and set it to something else than Marquee if this is set.
Also, be sure to call your method after the value has been changed, not before.
ASKER
The style was (and still is) set to Blocks, and the method call to set the progress bar text is after the progress bar value is changed. But even when no change is occurring to the progress bar value, the animation occurs and wipes out the text.
Brad
Private Sub frmEditTraining_Shown(sender As Object, e As EventArgs) Handles Me.Shown
InitTrainingDone()
InitTrainingDue()
InitProgressBars()
SetProgressBarText()
End Sub
ThanksBrad
Sorry.
I just spent an hour playing with the stuff, trying to inherit from ProgressBar in order to change the way it works, but even when inheriting, the standard event triggers (OnPaint, OnPaintBackground and the likes) that are usually used on other controls for such purposes are not fired.
You might want to try one of the numerous alternative to the standard ProgressBar that are available through a quick search through Bing or Google.
I just spent an hour playing with the stuff, trying to inherit from ProgressBar in order to change the way it works, but even when inheriting, the standard event triggers (OnPaint, OnPaintBackground and the likes) that are usually used on other controls for such purposes are not fired.
You might want to try one of the numerous alternative to the standard ProgressBar that are available through a quick search through Bing or Google.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. The custom control works great.
Thanks
Brad
Thanks
Brad
Be sure to call your code each time you increment.