Click here to Skip to main content
11,701,855 members (62,639 online)
Click here to Skip to main content

The Amazing ProgressBar Control

, 7 Sep 2014 CPOL 120.9K 13K 264
Rate this:
Please Sign up or sign in to vote.
A progress bar which displays progress as passage through a simple maze.

Introduction

This is release 1.1.1 of the library. The .csproj files were converted for use in Visual Studio 2013, and the help files were updated to work with the latest release of Sandcastle Help File Builder (2014.5.31.0).

The AmazingProgressBar class is a drop-in replacement for the .NET 2.0 ProgressBar control, which displays progress as passage through a simple maze.

All public and protected classes, methods, and properties are fully documented using standard C# XML documentation comments. The project includes an HTML help file. Refer to the Overview section in the help file for more details on using the class.

The library download includes:

AmazingProgressBar.dll Class library
AmazingProgressBar.chm Help file

The demo download includes the above files, as well as:

AmazingExplorer.exe Sample program for experimenting with the various properties of the control.
AmazingExamples.exe Sample program displaying a variety of AmazingProgressBar examples.

The source download includes the source for all of the above programs, as well as the necessary files for building the help file.

Compatibility with Other .NET Framework Versions

The AmazingProgressBar library is compiled using .NET Framework version 2.0. To confirm that there were no issues with other framework versions, the compiled library was used by an application which was compiled, in turn, under .NET Framework versions 3.0, 3.5, 4.0, and 4.5. The AmazingProgressBar functioned properly with all of them.

Background

One day, while waiting for a long computational task to complete, I realized just how uninteresting the standard progress bar is. There had to be something more entertaining than a colored bar creeping slowly across the screen. After thinking about the problem for a while, I hit upon the idea of a progress bar which winds through a maze. And hence was born, the AmazingProgressBar control.

The AmazingProgressBar is pure eye candy. It won't make the task run any faster, but it might make the wait a bit less boring!

Using the Code

To use the AmazingProgressBar class, simply add it on an existing form:

AmazingProgressBar amaze = new AmazingProgressBar();
amaze.Location = new System.Drawing.Point(0, 0);
amaze.Size = new System.Drawing.Size(200, 50);
form.Controls.Add(amaze);

You can also replace any existing ProgressBar with AmazingProgressBar.

The progress direction and general style of the maze is determined by the MazeStyle property:

SingleRight Maze with a single path progressing left to right.
SingleLeft Maze with a single path progressing right to left.
SingleUp Maze with a single path progressing up.
SingleDown Maze with a single path progressing down.
SplitConvergeHorizontal Maze with two paths starting at the left and right ends, converging in the middle.
SplitConvergeVertical Maze with two paths starting at the top and bottom, converging in the middle.
SplitDivergeHorizontal Maze with two paths starting in the middle, ending at the left and right ends.
SplitDivergeVertical Maze with two paths starting in the middle, ending at the top and bottom.

The mazes generally have one route over which they can be traversed, but a small amount of branching may occur if RowCount is greater than 3. The maze direction(s) is/are the general direction(s), though there will always be twists and turns and some doubling back.

The size and complexity of the maze generally depends on the RowCount parameter. Set this parameter to fix the number of rows in the maze. A value of 1 results in a maze which looks just like a standard progress bar. A value of 2 results in a distinctly uninteresting maze. A value of 3 or more is strongly recommended.

The number of columns in the maze is the largest value given the size of the control, the current values of RowCount, WallSize, and BorderSize, and the rule that all cells in the maze must be square.

The ProgressBar.Style property can still be set. The Marquee style works as expected, but if the maze length is excessive, it may not work as fast as expected. The Blocks style is generally not as visually appealing as Continuous, though an interesting effect is to be had combining Blocks with a zero WallSize.

The following code segment shows how to set the Style, MazeStyle, and the number of rows.

// Assumes "AmazingProgressBar amaze" already declared and initialized
amaze.Style = ProgressBarStyle.Continous;
amaze.MazeStyle = MazeStyleType.SingleLeft;
amaze.RowCount = 4;

If the control cannot generate a maze, then the control is filled with a pink - on - black ripple pattern. This is usually the result of RowCount being too high or too low.

The filled cells inside the maze can either all be the same fixed color, or follow a color gradient. This is determined by the Gradient property:

None No gradient coloring. All filled cells are ForeColor.
Rows Each row in the maze is a different color, spanning a gradient with the first row being GradientStartColor, and the last row being GradientEndColor.
Columns Each column in the maze is a different color, spanning a gradient with the first column being GradientStartColor, and the last column being GradientEndColor.
Flow Each cell in the maze is a different color, spanning a gradient with the first cell being GradientStartColor, and the last cell being GradientEndColor.

All unfilled cells are always BackColor.

The maze walls are visible if WallSize is greater than zero. The walls can only be one fixed color, as indicated by the WallColor property.

The maze border can either be one fixed color, or a gradient from that fixed color to the default control color. The maze border can also have round corners.

The following code segment shows how to set the various color properties.

// Assumes "AmazingProgressBar amaze" already declared and initialized
amaze.Gradient = GradientType.Rows;
amaze.GradientStartColor = Color.LightBlue;
amaze.GradientEndColor = Color.DarkBlue;

amaze.BorderSize = 2;
amaze.BorderColor = Color.LightGreen;
amaze.BorderGradient = false;
amaze.BorderRoundCorners = true;

amaze.BackColor = Color.White;

How the Maze is Generated

There are many ways to generate a maze. This control required an algorithm to generate a maze which flowed in a particular direction with minimal branching, and to do so quickly and with limited memory overhead.

The SimpleMap class does the job. It is a static class for generating mazes with but one route in a specified direction. It works well most of the time, but for values of RowCount greater than 3, it occasionally does miss some cells, resulting in branches in the maze.

Following are the instructions for generating a single path maze. The directions used - forward, backward, and sideways - depend on the direction parameter. For example, if direction is Dir.E, then forward is East, backward is West, and sideways is North or South.

Start at one of the most backward corner cells. Repeatedly follow these rules (in order) to determine the next cell. Stop when all directions are blocked.

  1. If only one direction is possible, go in that direction.
  2. If you can go backwards, go that direction.
  3. If there is only one empty cell in a sideways direction, go in that direction.
  4. If there is more than one empty cell in both of the sideways directions, randomly pick one of those directions.
  5. Pick a random direction from the ones available; but you are only allowed to go forward if:
    1. at a sideways edge, and
    2. more than two steps from the forward most end, and
    3. back most filled column is not more than three steps backward.

Rules #2 and #5 are there to ensure that the maze does not get too far ahead before winding back.

Once a cell is reached where all the directions are blocked, the above rules no longer work. At this point, for each unused cell: randomly pick one direction and make the direction passable. This will result in branches within the maze, but it ensures that there are no skipped or unused cells.

History

  • September 7, 2014 - Release 1.1.1
    • Converted .csproj files to Visual Studio 2013 format.
    • Converted help files to work with SandCastle Help File Builder 2014.5.31.0.
  • May 3, 2011 - Release 1.1
    • Added Split... maze styles.
    • Added AmazingProgressBar.BorderRoundCorners member.
  • April 17, 2011 - First release

License

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

Share

About the Author

Graham Wilson
Software Developer (Senior)
Canada Canada
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
iDesmet19-May-11 8:13
memberiDesmet19-May-11 8:13 
GeneralMy vote of 5 Pin
Slacker00718-May-11 2:00
memberSlacker00718-May-11 2:00 
GeneralMy Vote of 5 Pin
RaviRanjankr15-May-11 0:15
memberRaviRanjankr15-May-11 0:15 
GeneralAmazing Pin
CIDev13-May-11 4:34
memberCIDev13-May-11 4:34 
GeneralMy vote of 5 Pin
Nagy Vilmos13-May-11 3:36
memberNagy Vilmos13-May-11 3:36 
GeneralExcellent but a tiny problem Pin
Xmen W.K.12-May-11 16:26
memberXmen W.K.12-May-11 16:26 
GeneralRe: Excellent but a tiny problem Pin
Graham Wilson13-May-11 1:42
memberGraham Wilson13-May-11 1:42 
GeneralMy vote of 5 Pin
Bigdeak10-May-11 23:44
memberBigdeak10-May-11 23:44 
GeneralRe: My vote of 5 Pin
Graham Wilson11-May-11 11:10
memberGraham Wilson11-May-11 11:10 
GeneralMy vote of 5 Pin
E$w@r10-May-11 18:13
memberE$w@r10-May-11 18:13 
GeneralMy vote of 5 Pin
msmits9-May-11 22:18
membermsmits9-May-11 22:18 
GeneralTerrible! Pin
msmits9-May-11 22:18
membermsmits9-May-11 22:18 
GeneralMy vote of 5 Pin
Marc A. Brown5-May-11 9:04
memberMarc A. Brown5-May-11 9:04 
GeneralVery inventive! Pin
Ravi Bhavnani5-May-11 8:58
memberRavi Bhavnani5-May-11 8:58 
Got my 5! Thumbs Up | :thumbsup:

/ravi
My new year resolution: 2048 x 1536
Home | Articles | My .NET bits | Freeware
ravib(at)ravib(dot)com

GeneralMy vote of 5 Pin
Prasad Khandekar4-May-11 23:10
memberPrasad Khandekar4-May-11 23:10 
GeneralMy vote of 4 Pin
Rhuros4-May-11 22:02
memberRhuros4-May-11 22:02 
GeneralMy vote of 5 Pin
Bill SerGio, Infomercial King4-May-11 20:27
memberBill SerGio, Infomercial King4-May-11 20:27 
GeneralRe: My vote of 5 Pin
Graham Wilson5-May-11 13:17
memberGraham Wilson5-May-11 13:17 
GeneralIt's worth the wait. Pin
gaps964-May-11 19:19
membergaps964-May-11 19:19 
GeneralMy vote of 4 Pin
Michael Rawi4-May-11 16:56
memberMichael Rawi4-May-11 16:56 
GeneralThis is aMAZEing Pin
Marcelo Ricardo de Oliveira25-Apr-11 12:33
mvpMarcelo Ricardo de Oliveira25-Apr-11 12:33 
GeneralThis Progress Bar SUCKS .... Pin
Gary Noter19-Apr-11 9:04
memberGary Noter19-Apr-11 9:04 
GeneralRe: This Progress Bar SUCKS .... Pin
Graham Wilson19-Apr-11 17:19
memberGraham Wilson19-Apr-11 17:19 
GeneralMy vote of 5 Pin
Aschratt19-Apr-11 6:17
memberAschratt19-Apr-11 6:17 
GeneralMy vote of 5 Pin
ctrueman19-Apr-11 3:49
memberctrueman19-Apr-11 3:49 
GeneralMy vote of 5 Pin
Yvan Rodrigues19-Apr-11 2:31
memberYvan Rodrigues19-Apr-11 2:31 
GeneralMy vote of 5 Pin
chrisclarke1119-Apr-11 0:53
memberchrisclarke1119-Apr-11 0:53 
GeneralMy vote of 5 Pin
graham the programmmer18-Apr-11 23:13
membergraham the programmmer18-Apr-11 23:13 
GeneralMy vote of 5 Pin
Patel Maulik18-Apr-11 23:11
memberPatel Maulik18-Apr-11 23:11 
GeneralMy vote of 5 Pin
Kim Togo18-Apr-11 22:15
memberKim Togo18-Apr-11 22:15 
GeneralGreat idea! Pin
Jakob Lund Krarup18-Apr-11 22:14
memberJakob Lund Krarup18-Apr-11 22:14 
GeneralMy vote of 5 Pin
Geordie_Wilber18-Apr-11 20:31
memberGeordie_Wilber18-Apr-11 20:31 
GeneralWrong year in the history??? Pin
chrisbray18-Apr-11 19:19
memberchrisbray18-Apr-11 19:19 
GeneralRe: Wrong year in the history??? Pin
Graham Wilson19-Apr-11 1:37
memberGraham Wilson19-Apr-11 1:37 
GeneralMy vote of 5 Pin
hfut_short18-Apr-11 16:33
memberhfut_short18-Apr-11 16:33 
GeneralMy vote of 5 Pin
mjbohn18-Apr-11 10:32
membermjbohn18-Apr-11 10:32 
GeneralMy vote of 5 Pin
burak29918-Apr-11 5:56
memberburak29918-Apr-11 5:56 
GeneralMy vote of 5 Pin
Niklas Lindquist18-Apr-11 2:45
memberNiklas Lindquist18-Apr-11 2:45 
GeneralMy vote of 4 Pin
jawed.ace17-Apr-11 23:15
memberjawed.ace17-Apr-11 23:15 
GeneralMy vote of 5 Pin
MickeyWu17-Apr-11 22:19
memberMickeyWu17-Apr-11 22:19 
GeneralMy work collegue also did something you may enjoy Pin
Sacha Barber17-Apr-11 21:42
mvpSacha Barber17-Apr-11 21:42 
GeneralMy vote of 4 Pin
Sangunni17-Apr-11 21:01
memberSangunni17-Apr-11 21:01 
GeneralInnovative Pin
Mehdi Gholam17-Apr-11 20:52
memberMehdi Gholam17-Apr-11 20:52 
GeneralDont have an immediate use for it, but it is fun Pin
Sacha Barber17-Apr-11 19:58
mvpSacha Barber17-Apr-11 19:58 
GeneralMy vote of 5 Pin
JF201517-Apr-11 19:46
memberJF201517-Apr-11 19:46 
GeneralI agree Pin
Paul Selormey17-Apr-11 18:18
memberPaul Selormey17-Apr-11 18:18 
GeneralMy vote of 5 Pin
sam.hill17-Apr-11 15:18
membersam.hill17-Apr-11 15:18 

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.150819.1 | Last Updated 7 Sep 2014
Article Copyright 2011 by Graham Wilson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid