Click here to Skip to main content
Click here to Skip to main content

A Smooth ProgressBar for everyone! Part Duex

, 28 Feb 2005
Rate this:
Please Sign up or sign in to vote.
A versatile ProgressBar control featuring vertical and horizontal mode, gradients and more.

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():

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:

<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

Share

About the Author

Stumpy842

United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberfixo1-Aug-10 20:07 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Feb 2005
Article Copyright 2005 by Stumpy842
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid