I've completely reworked the code for my SmoothProgressBar and it now features the ability to show the foreground and background of the control with a gradient. This feature is optional and defaults to a solid foreground and background, just as the original SmoothProgressBar control had. I've decided to post this version as a new article in order that you may compare the code techniques with the original.
Please refer to the first article for background info about this control and my reason for creating it.
Using the code
I've added several new properties and changed a couple of things from the original control. I discovered that I could have a property named
Step if it was declared with surrounding square brackets, i.e.:
Public Property [Step]() As Integer
Declaring it without the square brackets causes an error because
Step is a Keyword in VB, so Visual Studio complains: Keyword is not valid as an identifier.
I also changed the method name for incrementing the
Value property from
PerformStep() to make it easier to substitute this control for the
ProgressBar included in .NET, since that is the name used in the .NET control.
To support the display of gradients, there are several new properties associated with the control. First of all, the
ProgressBarColor property has been renamed to
BarColor1. In addition, there is a
BarColor2 property used to set the end color of the gradient blend for the bar (foreground). Of course there are also
BackColor2 properties with corresponding effect for the control's background colors.
Horizontal property has been renamed to
Orientation, and the
Reverse property is now
Direction. They are no longer
Boolean, instead using values from
Enums to more accurately describe their function.
BackColorStyle default to
Solid; to use gradient blends change these to
BackGradientMode enumerate the standard gradient direction values
BackSigmaMode default to
Normal. When set to
SigmaBell, the properties
BackSigmaScale are used to shape the bell-curve defining the center and falloff rate of the gradient(s).
BarGradientStretch controls whether or not the gradient blend of the bar (foreground) stretches as the bar progresses. If this doesn't make sense, just download the sample code and play with these property values to get a better idea of what they are doing.
Points of Interest
I've abandoned the technique of calculating an update Region in the setter code portion of the
Value property. This was originally done to allow updating only the portion of the control which had changed from the previous value. I've since decided it would be less code to simply Invalidate the entire control after changing the
Value property, but this causes flicker when the control is repainted, ergo the update Region code. Instead I've inherited the control from
Control instead of
UserControl, and set the
Style to use double-buffering to avoid flicker. This is done with the following statement, placed in the
Sub New() after the call to
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer _
Or ControlStyles.UserPaint, True)
It's worth noting that the
UserPaint style only applies to classes derived from
Another point worth noting is that some of the properties from
Control aren't needed for
SmoothProgressBar, and are suppressed from being shown in the PropertyGrid by setting the
Browsable attribute to
False. Here's an example:
Shadows ReadOnly Property Font() As Font
The property must be declared
Shadows or Visual Studio complains:
property 'Font' shadows an overridable method in a base class.
To override the base method, this method must be declared 'Overrides'.
I think this will be my final effort towards creating a better ProgressBar, I'm fairly satisfied with the results. Please download the source and the demo project, compare it with the first article and leave a comment! I noticed that the original article has nearly 2500 views but has been rated by only two people, so if you like this article and this control (or even if you don't like it) please take a moment to give it a rating. I'm waiting to hear from you!
- Feb 19th, 2005
- Feb 28th, 2005
- Added SPB_Help.zip containing SmoothProgressBar.chm help file and SPB.xml for Intellisense support in Visual Studio (see the Read Me.txt file in the download for details).