EDN Admin
Well-known member
Is there a way to make ProgressBarRenderer.DrawHorizontalChunks actually work the same as the standard ProgressBar rendering?
If you create a Class that Inherits ProgressBar and override the OnPaint event then you have to render the Empty ProgressBar and its fill% manually. This pretty easy with the ProgressBarRenderer. However, the DrawHorizontalChunks function is ugly compared
to how a standard ProgressBar renders itself.
<pre class="prettyprint lang-vb Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, New Rectangle(0, 0, CInt(e.ClipRectangle.Width * (_Progress / 100)), e.ClipRectangle.Height))
End Sub[/code]
The visual problem is that the DrawHorizontalBar function creates the same empty ProgressBar that you normally see, with curved corners. However, the DrawHorizontalChunks function goes with a normal rectangle, so its corners overlap those of its own background.
It lacks the slightly darker colour at the far left and right and doesnt have the thin band that moves gently along whatever portion is currently filled to tell you everything is still working.
The cause of the work was simply to get a ProgressBar that looks and behaves exactly as the standard one, but with some text written on top of it (showing various forms of progress).
Thats the basic question, the notes below are for reference and dont necessarily need reading.
Ive tried various routes, mostly discarding the ProgressBarRenderer and using e.Graphics.Fill... functions such as FillRectangle, FillRegion etc. I havent managed to get any of them working in a pretty way and the code just kept growing (hence slowing
everything down) especially when I tried creating a region with AddArc, AddLine etc., it worked but boy was it ugly.
I also tried using Powerpacks.SimpleShapes.Rectangles, which allow rounded corners, but they get drawn on top of the ProgressBar so anything you draw to ProgressBar OnPaint e.Graphics (e.g. text) gets obliterated by the shapes on top of it.
I also have a second more minor issue in that I Shadowed the value property (for various reasons), so PerformStep (which then has to be Shadowed to keep the Value property in check) causes it to increase in blocks rather than smoothly growing between
the two Values (old value growing to old value + step); the only solution I can see is to extend the code in the Shadows Sub PerformStep code to move the Value property gradually between the old and new values.
Mike
View the full article
If you create a Class that Inherits ProgressBar and override the OnPaint event then you have to render the Empty ProgressBar and its fill% manually. This pretty easy with the ProgressBarRenderer. However, the DrawHorizontalChunks function is ugly compared
to how a standard ProgressBar renders itself.
<pre class="prettyprint lang-vb Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, e.ClipRectangle)
ProgressBarRenderer.DrawHorizontalChunks(e.Graphics, New Rectangle(0, 0, CInt(e.ClipRectangle.Width * (_Progress / 100)), e.ClipRectangle.Height))
End Sub[/code]
The visual problem is that the DrawHorizontalBar function creates the same empty ProgressBar that you normally see, with curved corners. However, the DrawHorizontalChunks function goes with a normal rectangle, so its corners overlap those of its own background.
It lacks the slightly darker colour at the far left and right and doesnt have the thin band that moves gently along whatever portion is currently filled to tell you everything is still working.
The cause of the work was simply to get a ProgressBar that looks and behaves exactly as the standard one, but with some text written on top of it (showing various forms of progress).
Thats the basic question, the notes below are for reference and dont necessarily need reading.
Ive tried various routes, mostly discarding the ProgressBarRenderer and using e.Graphics.Fill... functions such as FillRectangle, FillRegion etc. I havent managed to get any of them working in a pretty way and the code just kept growing (hence slowing
everything down) especially when I tried creating a region with AddArc, AddLine etc., it worked but boy was it ugly.
I also tried using Powerpacks.SimpleShapes.Rectangles, which allow rounded corners, but they get drawn on top of the ProgressBar so anything you draw to ProgressBar OnPaint e.Graphics (e.g. text) gets obliterated by the shapes on top of it.
I also have a second more minor issue in that I Shadowed the value property (for various reasons), so PerformStep (which then has to be Shadowed to keep the Value property in check) causes it to increase in blocks rather than smoothly growing between
the two Values (old value growing to old value + step); the only solution I can see is to extend the code in the Shadows Sub PerformStep code to move the Value property gradually between the old and new values.
Mike
View the full article