Hello,
Im sure this is simple, but after confusing myself searching around for the correct answer I thought it best to ask....
Here's what I have: A full screen app with lots of timer based sampling and graphical display of values alongside which I wanted a circular type progress bar. I searched around and found a really neat solution (thanks to Matt Wilko):
Private Sub DrawProgress(g As Graphics, rect As Rectangle, percentage As Single)
Dim progressAngle = CSng(360 / 100 * percentage)
Dim remainderAngle = 360 - progressAngle
Using progressPen As New Pen(ThmVSEndColNormal, 4), remainderPen As New Pen(ThmTextColBody, 4)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.DrawArc(progressPen, rect, -90, progressAngle)
g.DrawArc(remainderPen, rect, progressAngle - 90, remainderAngle)
End Using
Using fnt As New Font(Me.Font.FontFamily, 14)
Dim text As String = percentage.ToString + "%"
Dim textSize = g.MeasureString(text, fnt)
Dim textPoint As New Point(CInt(rect.Left + (rect.Width / 2) - (textSize.Width / 2)), CInt(rect.Top + (rect.Height / 2) - (textSize.Height / 2)))
g.DrawString(text, fnt, Brushes.White, textPoint)
End Using
End Sub
In the example Matt calls the routine in the Paint event thus:
DrawProgress(e.Graphics, New Rectangle(GrpControl.Left + 15, GrpControl.Top + ProgCountDown.Top, ProgCountDown.Height, ProgCountDown.Height), 40)
where 40 is the value required, its static here but obviously needs to change.
Now, I can assign a global variable to the percentage I need, send that off to the 'DrawProgress' sub and then refresh or invalidate the the form each time the value changes which
does work, but the whole screen and all the controls refresh causing a nasty jitter.
I'm still getting to grips with .net so forgive my lack of understanding, but I could do with some advice on how to handle this properly. It seems to me that I perhaps need to invalidate just the graphics object created in the DrawProgress sub so Im not forcing the whole screen to re-paint.
Eventually I'd like to make control class for this circular progress bar as it's really neat and I'll use it a lot but that's for another day....