Click here to Skip to main content
15,125,074 members
Articles / Programming Languages / Visual Basic
Posted 2 Apr 2007


143 bookmarked

Two-Way Progress Bar

Rate me:
Please Sign up or sign in to vote.
4.77/5 (25 votes)
6 Aug 2008CPOL4 min read
A Progress Bar User Control that uses a couple of intermediate level ComponentModel properties
Screenshot - SplitProgressBar.gif

Latest Update

The original control was not written to include thread-safety compliance. That has been corrected and is available in the new download(s).
Thanks to everyone for all the very kind words!


As an application developer, it is not uncommon to run into a specific UI requirement that you cannot fulfill by using a purchased control. Often times you'll find 3rd party controls that come close but don't quite get you to your goal. Your options are to alter the UI Design for this particular requirement, or write your own control.


That's the origin of this control. My application was performing a rather lengthy database update that involved a large group of parent objects and with each parent object, a large number of child-objects needed to be updated as well. The entire process would take 30 seconds to several minutes and I didn't want my users staring at an hourglass for that period of time wondering if they'd locked up.

I started out with a standard Progress Bar which was fine until I noticed several 'ticks' were so lengthy that again my concern went back to the users and not wanting to force them to sit staring at a screen that was dead for a more than a few seconds.

To solve this problem, I could have just stacked two progress bars on top of each other and updated them individually — but being a programmer, I could find no valid reason not to over-engineer this task into a single, self-contained control!

Using the Control in your Project

While in Visual Studio, right-click on the Toolbox in the Tab you wish to add the Control. Click 'Choose Items...' and navigate to where you saved the SplitProgressBar.dll. Select the DLL and click 'OK'.

This will add the control to your toolbox and you're now ready to drag it onto your forms for use.


  • BarBackColor is the background color of the panel behind the ProgressBar Cells.
  • BorderColor is color used in the lines surrounding the ProgressBar.
  • TextBackColor is the background color of the panel behind the Label.
  • TextColor is the Label's forecolor.
  • BarBottomColor and BarTopColor are the colors to use for the ProgressBar Cells.
  • BarBottom.BarMax is the upper limit that .BarValue can reach.
  • BarBottom.BarMin is the lower limit that .BarValue can reach.
  • BarBottom.BarStep tells the progress bar how to increment .BarValue every time .PerformBottomStep is pushed.
  • BarBottom.BarValue is the actual value of our ProgressBar.
  • BarTop is identical to BarBottom.
  • GradientBars if true, the control will attempt to fill in the cells using a gradient pattern.
  • SyncTopAndBottom if true, the control will ignore the BarBottom values and draw one, large solid cell using the BarTop values.
  • PanelText.TextLabel is the Text displayed in the Label Panel.
  • PanelText.TextPanelAlignment Left, Center or Right horizontal alignment used for the Label.
  • PanelText.TextPanelAutosize if true, the width of the Label Panel will be calculated based on the text.
  • PanelText.TextPanelWidth use this to adjust the size of your Label.
    *Only valid if TextPanelAutosize = False*.

Sample Usage

Private Sub ProcessSomething()
    ' Setup our progress bar to use ONE large cell and to paint the cells as

    With ProgBar
        .SyncTopAndBottom = True
        .GradientBars = True
        .BarTop.BarMax = ElementsToProcess.Count
        .BarTop.BarStep = 50
        .BarTop.BarValue = 0
    End With
    Dim CurrentElement As Integer
    For Each Element As SomeElement In ElementsToProcess

        ' Your code here


        ' Increment our counter

        CurrentElement += 1
        ' If we're ready to update the progress bar - go do it.

        If CurrentElement Mod ProgBar.BarTop.BarStep = 0 Then
        End If
End Sub

Using both the top and bottom bars at the same time is very simple: just set .SyncTopAndBottom=False and setup your .BarBottom properties the same way you setup the .BarTop properties.

*Note*: If your control height results in cells that are smaller than 6 pixels, a solid color will be used to fill in the cells regardless of your .GradientBars value.

Cool ComponentModel Properties

Have you ever had one property alter the value of another property during design time? To get the properties window for the control to refresh the values, use the RefreshProperties to force the update like this:

<refreshproperties(refreshproperties.all)> _
Public Property BarMin() As Integer
        Return _Min
    End Get
    Set(ByVal value As Integer)
        If _Min <> value Then
            _Min = value
            If _Min > _Max Then Me.BarMax = _Min
            RaiseEvent BarClassChanged()
        End If
    End Set
End Property</refreshproperties(refreshproperties.all)>

Ever want to "hide" unused properties? Not all of them are "hidable" but for those that are, try this:

<Browsable(False)> _
Public Overrides Property Autosize() As Boolean
        Return MyBase.AutoSize
    End Get
    Set(ByVal value As Boolean)
        MyBase.AutoSize = value
    End Set
End Property

Points of Interest

This is the first control I wrote that uses expandable properties (like Size, Padding, Location, etc.) While very nice to have, figuring out how to set the properties up like this caused me a number of heartaches not the least of which is there's almost no documentation on how to create, configure or use expandable properties (that I was able to find!)

A weirdness that happens quite frequently and I have yet to figure out why: When the control is first placed on your form, click on the control and scroll the properties window down to BarBottom and look at the value displayed: "0,0,0,0" which are the default startup settings.

If you modify the Converter and rebuild the SplitProgressBar class — instead of seeing the Sub-Property values, you'll see the NAME of the class like this, "SplitProgressBar.BarClass"

At this point, you have to remove SplitProgressBar from the main project's reference list — and re-add it. Restarting Visual Studio will resolve this issue as well but since I was never intending the developer to change the sub-properties as a single line of comma-delimited text by filling in the parent property, I'm actually OK when this happens.

In fact, that's one improvement I'd like to make for the control: I would like NO text be displayed next to the parent property when collapsed. If anyone knows how to pull this off, PLEASE let me know!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
kaszur23-Aug-11 10:26
Memberkaszur23-Aug-11 10:26 
GeneralThanks! Pin
Member 241295516-Jul-09 11:40
MemberMember 241295516-Jul-09 11:40 
GeneralVery Nice Pin
Paul Conrad2-Aug-08 20:40
professionalPaul Conrad2-Aug-08 20:40 
GeneralRe: Very Nice Pin
Elkay3-Aug-08 9:29
MemberElkay3-Aug-08 9:29 
GeneralRe: Very Nice Pin
Paul Conrad3-Aug-08 19:22
professionalPaul Conrad3-Aug-08 19:22 
GeneralRe: Very Nice Pin
Elkay3-Aug-08 19:31
MemberElkay3-Aug-08 19:31 
GeneralRe: Very Nice Pin
Paul Conrad3-Aug-08 19:34
professionalPaul Conrad3-Aug-08 19:34 
GeneralThread safety Pin
supercat931-Jul-08 15:57
Membersupercat931-Jul-08 15:57 
GeneralRe: Thread safety Pin
Elkay31-Jul-08 21:32
MemberElkay31-Jul-08 21:32 
GeneralRe: Thread safety Pin
supercat91-Aug-08 6:53
Membersupercat91-Aug-08 6:53 
Questionhi Pin
Schatak12-Sep-07 1:52
professionalSchatak12-Sep-07 1:52 
AnswerRe: hi Pin
Elkay12-Sep-07 7:16
MemberElkay12-Sep-07 7:16 
AnswerRe: hi Pin
The_Mega_ZZTer31-Jul-08 12:49
MemberThe_Mega_ZZTer31-Jul-08 12:49 

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.