5,699,431 members and growing! (16,393 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

XP like colour progress bar

By Ivan Mihaylov

A WinForms progress bar control.
C#.NET 1.1, Win2K, WinXP, Windows, .NET, GDI+, WinForms, Visual Studio, VS.NET2003, Dev

Posted: 30 Mar 2005
Updated: 30 Mar 2005
Views: 43,445
Bookmarked: 25 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 4.81 Rating: 3.83 out of 5
1 vote, 5.6%
1
0 votes, 0.0%
2
2 votes, 11.1%
3
8 votes, 44.4%
4
7 votes, 38.9%
5

Sample Image

Introduction

This is a simple progress bar control that imitates the XP visual style. The control inherits Windows.Forms.Control and the reason to add another progress bar here is that there was no XP style progress bar with the ability to change its colour. I needed a red coloured progress bar to indicate error but the normal XP progress bar does not allow colour change. Also, I needed that nice XP style because my program was using the XP visual styles. The bars are drawn just like the XP progress bar. The whole bars are drawn, not parts from them, depending on the value.

Background

For the progress bar, I used the very nice progress bar control developed by Alan Zhao. Basically, the main functionality is provided by him, I improved the painting of the control to make it XP like.

Control Properties

  • BarColor

    The primary color of ColorProgressBar.

  • BorderColor

    The border color of ColorProgressBar.

  • FillStyle

    Bar styles, "Solid" or "Dashed".

  • Maximum

    The maximum value of ColorProgressBar.

  • Minimum

    The minimum value or the initial value of ColorProgressBar.

  • Value

    The current value of ColorProgressBar.

  • Step

    The value of each increment or decrement when you call methods PerformStep() and PerformStepBack().

Control Methods

  • PerformStep()

    Call the PerformStep() method to increase the value set in the Step property.

  • PerformStepBack()

    Call the PerformStepBack() method to decrease the value set in the Step property.

  • Increment(int value)

    Call the Increment() method to increase the integer value you specify.

  • Decrement(int value)

    Call the Decrement() method to decrease the integer value you specify.

Painting code

// The region of the progress bar!

int leftbar = 1;
int topbar = 1;
int X = this.Width-1;
int Y = this.Height-1;
Point[] points = {   new Point(leftbar + 2, topbar), 
         new Point(X-2, topbar), 
         new Point(X-1, topbar + 1), 
         new Point(X, topbar + 2), 
         new Point(X, Y-3), 
         new Point(X-1, Y-2), 
         new Point(X-2, Y-1), 
         new Point(leftbar + 2, Y), 
         new Point(leftbar + 1, Y-2), 
         new Point(leftbar, Y-3), 
         new Point(leftbar, topbar + 2),
         new Point(leftbar + 1, topbar + 1),
        };    
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
Region reg = new Region(path);
e.Graphics.FillRegion(Brushes.White, reg);

This is the definition of the region of the progress bar.

Points of Interest

The project is interesting if you want to learn how to simulate and to draw controls like they are drawn in Windows XP.

History

No history yet.

Thanks

Thanks again to Alan Zhao for his great work. You can check out his work here.

Feedbacks

Please vote for this article.

And email me or leave your messages if you have:

  • bug reports
  • code improvements
  • any comments or suggestions.

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

About the Author

Ivan Mihaylov


Software engineer for TeamR3 Bulgaria.
Location: Bulgaria Bulgaria

Other popular C / C++ Language articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralNicememberabno6:23 2 Oct '07  
GeneralHow to use the codemembercraude1:07 1 Jan '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Mar 2005
Editor: Smitha Vijayan
Copyright 2005 by Ivan Mihaylov
Everything else Copyright © CodeProject, 1999-2008
Web11 | Advertise on the Code Project