Click here to Skip to main content
15,867,986 members
Articles / Programming Languages / Visual Basic
Article

A Smooth ProgressBar for everyone! Part Duex

Rate me:
Please Sign up or sign in to vote.
4.61/5 (72 votes)
28 Feb 20054 min read 196.8K   2.7K   66   44
A versatile ProgressBar control featuring vertical and horizontal mode, gradients and more.

Image 1

Introduction

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.

Background

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 Stepit() to 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 BackColor1 and BackColor2 properties with corresponding effect for the control's background colors.

The 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.

New properties BarColorStyle and BackColorStyle default to Solid; to use gradient blends change these to Gradient. BarGradientMode and BackGradientMode enumerate the standard gradient direction values Horizontal, Vertical, ForwardDiagonal and BackwardDiagonal.

BarSigmaMode and BackSigmaMode default to Normal. When set to SigmaBell, the properties BarSigmaFocus, BarSigmaScale, BackSigmaFocus and 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 InitializeComponent():

VB
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 Control.

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:

VB
<Browsable(False)> _
   Shadows ReadOnly Property Font() As Font
      Get
         Return MyBase.Font
      End Get
   End Property

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'.

Conclusion

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!

History

  • Feb 19th, 2005
    • Initial release.
  • 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).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 964319729-Nov-12 11:54
Member 964319729-Nov-12 11:54 
QuestionWorks beautifully -- Thank you. Pin
Texas_MO26-Nov-12 7:31
Texas_MO26-Nov-12 7:31 
GeneralMy vote of 5 Pin
sboulstridge15-Nov-12 8:54
sboulstridge15-Nov-12 8:54 
GeneralMy vote of 5 Pin
fixo1-Aug-10 19:07
fixo1-Aug-10 19:07 
GeneralVery nice article Pin
Sheikh Rahat Ali31-Jul-09 4:37
Sheikh Rahat Ali31-Jul-09 4:37 
GeneralMarquee Style Pin
windwrd011-Aug-08 9:40
windwrd011-Aug-08 9:40 
GeneralRefresh Problem Pin
John Maddox9-Aug-07 7:43
John Maddox9-Aug-07 7:43 
GeneralThanks Man!!! Pin
sspanogle16-Feb-07 5:34
sspanogle16-Feb-07 5:34 
GeneralRe: Thanks Man!!! Pin
Stumpy84218-Feb-07 5:30
Stumpy84218-Feb-07 5:30 
Generalplotting coordinates with vb application and saving it as dxf file. Pin
emmaddais22-Dec-06 2:31
emmaddais22-Dec-06 2:31 
GeneralGreat, but can't get IntelliSense to work Pin
wim.NET27-Jun-06 23:09
wim.NET27-Jun-06 23:09 
GeneralRe: Great, but can't get IntelliSense to work Pin
Stumpy84229-Jun-06 16:35
Stumpy84229-Jun-06 16:35 
GeneralSettings not saving correctly. Pin
VTHoodlum14-Mar-06 3:20
VTHoodlum14-Mar-06 3:20 
GeneralRe: Settings not saving correctly. Pin
Patrick Etc.5-Apr-06 11:02
Patrick Etc.5-Apr-06 11:02 
GeneralCan't get it to work Pin
Dan Demp14-Dec-05 11:44
Dan Demp14-Dec-05 11:44 
GeneralRe: Can't get it to work Pin
Stumpy84215-Dec-05 14:47
Stumpy84215-Dec-05 14:47 
GeneralDotnetbar Pin
Necklacer26-Oct-05 6:42
Necklacer26-Oct-05 6:42 
GeneralRe: Dotnetbar Pin
Stumpy84226-Oct-05 15:02
Stumpy84226-Oct-05 15:02 
GeneralRe: Dotnetbar Pin
Necklacer27-Oct-05 21:18
Necklacer27-Oct-05 21:18 
GeneralWOW but How..... Pin
NickJS18-Oct-05 14:35
NickJS18-Oct-05 14:35 
GeneralRe: WOW but How..... Pin
Stumpy84219-Oct-05 9:03
Stumpy84219-Oct-05 9:03 
GeneralRe: WOW but How..... Pin
NickJS22-Oct-05 2:04
NickJS22-Oct-05 2:04 
GeneralRe: WOW but How..... Pin
Stumpy84224-Oct-05 11:18
Stumpy84224-Oct-05 11:18 
GeneralAdded divisions Pin
Geoff Carlton22-Sep-05 15:56
Geoff Carlton22-Sep-05 15:56 
GeneralRe: Added divisions Pin
Stumpy84219-Oct-05 8:44
Stumpy84219-Oct-05 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.