Articles‎ > ‎



This is ProgressBar control with customizable look (currently has Vista and XP like renderers) and state support (Normal, Paused, Error). Also can work in system mode (ProgressBar painted by system).


When tested new Nomad in Windows Vista I've been impressed with new system ProgressBar look. After some investigating I've found that in addition to nice look progress bars in Vista has some new functions (one of them state support). Vista ProgressBar looks so good so I decided to write my own control that mimic Vista Progress bar on older OSes. With state support of course.

Doing the job

First of all I was needed to implement native states support in Vista. I have found good blog article and even ready to use solution to do this. To implement native progress bar look my control was inherited from System.Windows.Forms.ProgessBar instead of Control.

Second I decided not to limit new control with only Vista look, so IProgressBarRenderer interface was born. This interface is responsible to draw progress bar when it not in native mode. There is many ProgressBar controls on CodeProject site (which I visit regularly) but all of them lack customization.

I have taken xasthom progressbar control as base for my Vista style renderer (most of the code remain unchanged, but some optimization and cleanup has done, also I have dropped animated shine and added animated marquee code, because this control does not support marquees).

For Xp style progress bar algorithm is taken from another CodeProject article. Code was greatly optimized and changed. And marquee support added. Maybe other programmers do not use marquee mode? In other case I cannot understand lack of marquee logic in almost all custom progress bars.

Using the code

Using this control is very easy. It is add only several properties to standard ProgressBar. Two browsable properties: State and RenderMode and one public Renderer.

RenderMode is enumeration with three possible values: System, Vista, Custom. System means that all painting are performed by system, so it look differently on different OSes and states are supported only in Vista. Vista means that on Vista system mode is used, on other OSes control internally uses VistaProgressBarRenderer with state support. Custom render mode cannot be in design-time, it was set automatically when you assign your own IProgressBarRenderer implementation to Renderer property.

And State is used to set current ProgressBar state: Normal, Paused, Error. As I mentioned earlier this property does not work in certain circumstances.

There is two customizable ProgressBar renderers: VistaProgressBarRenderer and XPProgressBarRenderer. You can use these renderers in custom mode or write your own renderer.

Points of interest

Progress bar uses IProgressBarRenderer implementation to paint itself:

public interfaceIProgressBarRenderer
void DrawBackground(ProgressBarRenderEventArgs e);
void DrawBarValue(ProgressBarValueRenderEventArgs e);
void DrawMarquee(ProgressBarMarqueeRenderEventArgs e);
bool UpdateMarquee(ProgressBarMarqueeEventArgs e);

DrawBackground and DrawBarValue are self-describing. Custom marquee drawing logic need know current marquee position to draw. This is done through custom Tag property of ProgressBarMarqueeRenderEventArgs and ProgressBarMarqueeEventArgs classes. DrawMarquee was called from OnPaint method, UpdateMarquee was called on timer tick. So custom renderer can update Tag with any value it is needed, and then DrawMarquee uses this value to draw marquee in correct position.

Setting states on Vista was done by sending special message to ProgressBar:

private void SetVistaState(ProgressState state)
SendMessage(Handle, PBM_SETSTATE, (IntPtr)PBST_NORMAL, IntPtr.Zero);

switch (state)
SendMessage(Handle, PBM_SETSTATE, (IntPtr)PBST_PAUSED, IntPtr.Zero);
SendMessage(Handle, PBM_SETSTATE, (IntPtr)PBST_ERROR, IntPtr.Zero);

ProgressBar sometimes resets is state to Normal (for example Vista resets state response to progress bar position changing), so I also override OnHandleCreated and WndProc to fix this issue.

On non-Vista OSes state handling in Vista mode was done by changing ProgressBar color in the embedded VistaProgressBarRenderer.


As you can see this control is mix of many good ideas from other people, adding customization and easy to use to produce very useful and nice looking control. Hope you enjoy using it.


And again I must say that my English is far from perfect. So if you find some mistakes fell free to email me.

Downloads | mirror (Slow)
VistaProgressBar component sources, as well as small test application and precompiled demo.