Click here to Skip to main content
15,900,662 members
Articles / Programming Languages / Visual Basic

Fully Customizable XP Progress Bar (with examples)

Rate me:
Please Sign up or sign in to vote.
4.80/5 (120 votes)
20 Jan 2015CPOL2 min read 407.1K   13.8K   257   81
A progress bar like the WinXP progress bar control, but completely customizable.

Image 1

Introduction

I've developed an XpProgressBar that looks like the one used by the default WinXP theme. I have added a lot of features to fully customize its look.

Very important !!!

If you update the position of the progress bar in a tight loop or in a CPU intensive area and you feel that the bar is not repainted, use the following code in the place where you have problem:

C#
Application.DoEvents();

Please don't use Invalidate(), .Refresh() or .Update(). This can result in low performance and sometimes these don't work.

XpProgressBar features

The control offers the following features:

  • Good performance

    The XpProgressBar doesn't use much of the CPU because it uses a double buffer feature that performs painting operations offline to an image and later to the screen (this works at least three times faster).

  • Non flicking double buffer

    This control is implemented with a double buffer to provide smooth animation without any flicking and small paint time.

  • Anti alias text

    All the strings painted in the progress bar are drawn using anti alias hint to provide better quality.

  • Text shadow

    You can set the shadow to the text and customize its color and the alpha channel.

  • Fully customizable

    As you can see, every property of the progress bar can be set to provide a beautiful look.

Image 2

The properties of the control:

  • BackgroundImage
  • ColorBackground
  • ColorBarBorder
  • ColorBarCenter
  • ColorsXp

    Reset the colors to WinXP default.

  • ColorText
  • GradientStyle
  • SteepDistance
  • SteepWidth
  • TextShadow
  • TextShadowAlpha

GradientStyle

You can set the GradientStyle property to obtain some of these styles:

Image 3

Animation sample

The following picture shows an animation sample with different timers and looks:

Image 4

License

The control and the source code are completely free for commercial and non commercial use.

History

  • 2005-10-1: Article submitted.
    • 1.5
      • Improved the performance of Paint algorithms.
      • Alpha text
      • The image on the ProgressBar looks like a logo (with alpha of course, jeje).
      • Can disable Anti Alias Text.
    • 2.0
      • Vertical ProgressBar (not only horizontal)
      • Text align
      • Border color

Updates

Visit my page Marcos Meli and come back with updates soon.

License

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


Written By
Architect Devoo
Argentina Argentina
Marcos Meli v1.0 was released at august of 1980 by Francisco and Mabel Inc.
He´s from Bahia Blanca, Argentina.

He enjoy developing from the 12 years, has a degree in Computer Science, and of course, love this site and .NET in general.

He is the lead developer of the FileHelpers Library.

Marcos is also the co-funder of Devoo.Net.
A company that provides Object Oriented Components & Libraries for .NET developers (mostly open source)

Comments and Discussions

 
GeneralThanks ! Pin
dapoussin23-Dec-05 5:13
dapoussin23-Dec-05 5:13 
GeneralRe: Thanks to you Pin
Marcos Meli25-Jan-06 7:05
Marcos Meli25-Jan-06 7:05 
QuestionVertical? Pin
John Boero6-Dec-05 5:20
John Boero6-Dec-05 5:20 
AnswerRe: Vertical? Pin
Marcos Meli6-Dec-05 9:35
Marcos Meli6-Dec-05 9:35 
AnswerRe: Vertical? Pin
DesaBoy11-Jan-06 1:24
DesaBoy11-Jan-06 1:24 
GeneralApplication.DoEvents is not the answer! Pin
ekriel28-Nov-05 6:05
ekriel28-Nov-05 6:05 
AnswerBut Application.DoEvents is the answer for many people Pin
Marcos Meli28-Nov-05 11:44
Marcos Meli28-Nov-05 11:44 
GeneralRe: But Application.DoEvents is the answer for many people Pin
ekriel29-Nov-05 6:21
ekriel29-Nov-05 6:21 
I agree with you, DoEvents does work in many situations. Especially a simple progress-bar situation where nothing else could/should be going on in the background.

Like I mentioned in my first comment, I'm of the mindset of just doing it 'right' the first time, and being reasonably sure it won't come back to bite me in the rear. I try to take a 'best-practices' approach to most things.

An example of what I consider doing-it-right-the-first time:

I've created a ProgressForm -- it's just a simple Form with a ProgressBar. The constructor takes a delegate to a 'worker' method. This ProgressForm, upon loading and showing, prepares and starts a BackgroundWorker. The BackgroundWorker calls the specified worker delegate. The worker method gets a handle to the BackgroundWorker, through which it can indicate it's progress back to the ProgressForm's progress bar. The heavy worker method hammers the CPU, yet the UI is still responsive, and with no DoEvents -- win-win. If you didn't know better, you'd never even know that it's multithreaded. The best part? The progress form is completely generic, it cares not one bit about your worker method. Code once, use it many times.


I've heard people many times say they've been using DoEvents for -years- and have never experienced a problem. I was the same. I understand how hard it is to even think of a situation where using DoEvents could cause problems during the normal use of your application. As such, let me describe the first time DoEvents gave me a hard time. (Forgive me, this is a bit long-winded, and rambly Sleepy | :zzz: )

I was working on an application that used a GPS for input to a mapping application. The GPS was connected to a COM port. When the COM port's buffer filled with data from the GPS, a "BufferFull" event was raised. In that BufferFull event handler, I parsed and processed the data from the GPS into a format the application could use. After the data was processed, secondary events were raised (by my code,) to indicate to other parts of the application that processed information had been captured, parsed, processed, and was ready for it to use.

The operations in some of these secondary event handlers were a bit on the 'heavy' side of things because they had to interact with the mapping API. Fortunately (unfortunately, actually,) in most cases, the load was never very heavy, and no problems were ever experienced. But still, to ensure the UI was responsive, I enlisted the use of a few DoEvents here-n-there where I thought the code could hang-up the UI on a larger-than-average data set.

DoEvents came back to haunt me when we picked up a user who's map data was much larger than anything we'd dealt with before. As can be expected, those heavy secondary-processing operations were taking longer to process through the mapping API. When those heavy methods fired-off a DoEvents in the past, it simply refreshed the UI because the UI Paint events were the only things in the event queue.

Not anymore.

With this larger-than-average data set causing the heavy secondary operation to take longer than expected, more than UI Paint events were sitting in the event queue -- COM port BufferFull events were sitting there as well! Data was coming in faster than it could be used! Sigh | :sigh:

So, in the middle of the data being secondarily processed against the mapping API, new data was coming in, getting parsed/processed, and then secondarily processed, all before the first data was secondarily processed! Sometimes the problem would 'uncongest' and catch up, giving the user, at the worst, strange results. Usually, it would cripple the app, and bring it to it's knees.

All this, in an app that had been working for literally more than a years time, now brought to it's knees because DoEvents was used to refresh the UI.



So, in conclusion, I'm only looking to offer you my advice. I used to be a use DoEvents all the time. No longer.
GeneralRe: But Application.DoEvents is the answer for many people Pin
Scott S.30-Nov-05 1:58
Scott S.30-Nov-05 1:58 
QuestionData processing from local to Web Service Pin
LNHockey21-Nov-05 21:21
LNHockey21-Nov-05 21:21 
AnswerRe: Data processing from local to Web Service Pin
Marcos Meli28-Nov-05 11:27
Marcos Meli28-Nov-05 11:27 
General[Message Deleted] Pin
nameoraliasnameoralias14-Nov-05 14:49
nameoraliasnameoralias14-Nov-05 14:49 
GeneralLooks Great Pin
shofb5-Nov-05 16:56
shofb5-Nov-05 16:56 
GeneralRe: Looks Great Pin
Marcos Meli8-Nov-05 7:13
Marcos Meli8-Nov-05 7:13 
QuestionLicensing Pin
Member 40776818-Oct-05 11:24
Member 40776818-Oct-05 11:24 
AnswerRe: Licensing Pin
Marcos Meli19-Oct-05 2:21
Marcos Meli19-Oct-05 2:21 
GeneralNeat little progress Bar Pin
Obaid ur Rehman4-Oct-05 21:25
Obaid ur Rehman4-Oct-05 21:25 
GeneralRe: Neat little progress Bar Pin
Marcos Meli5-Oct-05 8:22
Marcos Meli5-Oct-05 8:22 
GeneralNever ending progressbar Pin
Carl Mercier1-Oct-05 15:30
Carl Mercier1-Oct-05 15:30 
GeneralRe: Never ending progressbar Pin
Marcos Meli1-Oct-05 15:41
Marcos Meli1-Oct-05 15:41 
GeneralRe: Never ending progressbar Pin
Marcos Meli2-Oct-05 9:55
Marcos Meli2-Oct-05 9:55 
GeneralRe: Never ending progressbar Pin
Craig G Fraser2-Oct-05 23:30
Craig G Fraser2-Oct-05 23:30 
GeneralRe: Never ending progressbar Pin
rjn5-Oct-05 11:06
rjn5-Oct-05 11:06 
GeneralRe: Never ending progressbar Pin
Kent Boogaart5-Oct-05 17:11
Kent Boogaart5-Oct-05 17:11 

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.