Click here to Skip to main content
15,868,141 members
Articles / Programming Languages / C#

The Amazing ProgressBar Control

Rate me:
Please Sign up or sign in to vote.
4.96/5 (224 votes)
30 Dec 2022CPOL8 min read 497.5K   17.9K   326   115
A progress bar which displays progress as passage through a simple maze.

Introduction

This is release 2.0.0 of the library. There are incompatibilities with earlier (1.x) versions. To avoid conflicts, the library has been renamed to AmazingProgressBar2. Refer to the History section for more details.

The AmazingProgressBar2 control is a drop-in replacement for the .NET Windows Forms ProgressBar control, which displays progress as passage through a simple maze.

Image 1

The AmazingProgressBar2 control is compiled using .NET Framework 3.5, .NET Framework 4.6.2, and .NET 6.0.

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

The AmazingProgressBar2_200_Demo includes the following files:

  GAW.AmazingProgressBar2.Net462.dll   Library compiled for .NET Framework 4.6.2.
  GAW.AmazingProgressBar2.ExplorerApp.Net462.exe   Sample app for experimenting with the various properties of the control.
  GAW.AmazingProgressBar2.ExamplesApp.Net462.exe   Sample app displaying a variety of control examples.
  GAW.SimpleWidgets2.Net462.dll   SimpleWidgets2 library compiled for .NET Framework 4.6.2.

The AmazingProgressBar2_200_Library includes the following files:

  GAW.AmazingProgressBar2.Net35.dll   Library compiled for .NET Framework 3.5.
  GAW.AmazingProgressBar2.Net462.dll   Library compiled for .NET Framework 4.6.2.
  GAW.AmazingProgressBar2.Net60 (.dll,.deps.json)   Library compiled for .NET 6.0.
  GAW.AmazingProgressBar2.ExplorerApp.Net35.exe   Sample app for experimenting with the various properties of the control compiled for .NET Framework 3.5.
  GAW.AmazingProgressBar2.ExplorerApp.Net462.exe   Sample app for experimenting with the various properties of the control compiled for .NET Framework 4.6.2.
  GAW.AmazingProgressBar2.ExplorerApp.Net60 (.exe,.dll,.deps.json,.runtimeconfig.json)   Sample app for experimenting with the various properties of the control compiled for .NET 6.0.
  GAW_AmazingProgressBar2.chm   Help file (HTML Help format).
  GAW_AmazingProgressBar2.msha   Help file (MS Help Viewer format).
  GAW_AmazingProgressBar2.mshc   Help file (MS Help Viewer format).
  GAW.SimpleWidgets2.Net35.dll   SimpleWidgets2 library compiled for .NET Framework 3.5.
  GAW.SimpleWidgets2.Net462.dll   SimpleWidgets2 library compiled for .NET Framework 4.6.2.
  GAW.SimpleWidgets2.Net60 (.dll,.deps.json)   SimpleWidgets2 library compiled for .NET 6.0.

The AmazingProgressBar2_200_Source includes the source for all of the above programs (except GAW.SimpleWidgets2), as well as the necessary files for building the help files.

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 thus the Amazing ProgressBar control was born.

The AmazingProgressBar2 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 AmazingProgressBar2 class, simply add it on an existing form:

C#
AmazingProgressBar2 amaze = new AmazingProgressBar2();
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 AmazingProgressBar2.

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.

C#
// Assumes "AmazingProgressBar2 amaze" already declared and initialized
amaze.Style = ProgressBarStyle.Continous;
amaze.MazeStyle = AmazingProgressBarMazeStyle.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.

Image 2

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

ForeColor All filled cells are ForeColor.
GradientRows Each row in the maze is a different color, spanning a gradient with the first row being the first color in GradientColors, and the last row being the last color in GradientColors.
GradientColumns Each column in the maze is a different color, spanning a gradient with the first column being the first color in GradientColors, and the last column being the last color in GradientColors.
GradientFlow Each cell in the maze is a different color, spanning a gradient with the first cell being the first color in GradientColors, and the last cell being the last color in GradientColors.

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.

C#
// Assumes "AmazingProgressBar2 amaze" already declared and initialized
amaze.Gradient = GradientType.Rows;
amaze.ForeColor = Color.LightBlue;
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

  • December 30, 2022 - Release 2.0.0
    • Removed the properties StartColor and EndColor; added the property GradientColors.
    • Renamed AmazingProgressBar.MazeStyleType enumeration to AmazingProgressBarMazeStyle.
    • Renamed AmazingProgressBar.GradientType enumeration to AmazingProgressBarColorStyle and the Gradient property to ColorStyle.
    • Changed root namespace from GAW to GAW.Forms.
    • Changed project to use the SimpleWidgets2 library.
    • Changed project so that library and apps are compiled with Visual Studio 2022 for .NET Framework 3.5, .NET Framework 4.6.2, and .NET 6.0.
    • Changed help files to work with Sandcastle Help File Builder 2021.11.7.0.
    • Changed library and class names to AmazingProgressBar2 to avoid conflicts with earlier versions of the library.
  • 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)


Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiongood Pin
mediate12343-Apr-13 17:52
mediate12343-Apr-13 17:52 
GeneralExcellent..!! Pin
mayur.ce3-Dec-12 18:45
mayur.ce3-Dec-12 18:45 
GeneralMy vote of 5 Pin
TheCardinal6-Oct-12 12:23
TheCardinal6-Oct-12 12:23 
GeneralMy vote of 4 Pin
miguelsanc8-Aug-12 15:14
miguelsanc8-Aug-12 15:14 
GeneralMy vote of 5 Pin
Reza Ahmadi1-Apr-12 7:32
Reza Ahmadi1-Apr-12 7:32 
Questionvery good Pin
renegade31-Mar-12 17:13
renegade31-Mar-12 17:13 
GeneralMy vote of 5 Pin
Jαved29-Mar-12 1:01
professionalJαved29-Mar-12 1:01 
GeneralMy vote of 5 Pin
Praveen Kullu23-Mar-12 18:58
Praveen Kullu23-Mar-12 18:58 
Excellent! just Excellent work
QuestionMy 5 Pin
JaPed20-Mar-12 19:55
JaPed20-Mar-12 19:55 
Questionthank you Pin
kartalyildirim2-Mar-12 2:33
kartalyildirim2-Mar-12 2:33 
GeneralMy vote of 5 Pin
Smithers-Jones29-Nov-11 21:53
Smithers-Jones29-Nov-11 21:53 
GeneralMy vote of 5 Pin
Hari Om Prakash Sharma25-Nov-11 0:56
Hari Om Prakash Sharma25-Nov-11 0:56 
GeneralJust wanted to say well done on monthly competition Pin
Sacha Barber1-Jun-11 0:47
Sacha Barber1-Jun-11 0:47 
GeneralRe: Just wanted to say well done on monthly competition Pin
Graham Wilson1-Jun-11 3:44
Graham Wilson1-Jun-11 3:44 
GeneralMy vote of 5 Pin
freedom16131-Jun-11 0:42
freedom16131-Jun-11 0:42 
GeneralMy vote of 5 Pin
Irwan Hassan31-May-11 19:09
Irwan Hassan31-May-11 19:09 
GeneralMy vote of 5 Pin
ashishkumar00831-May-11 12:10
ashishkumar00831-May-11 12:10 
GeneralMy vote of 5 Pin
Nitesh Kejriwal31-May-11 9:25
professionalNitesh Kejriwal31-May-11 9:25 
GeneralCongratulation Pin
ambarishtv30-May-11 23:07
ambarishtv30-May-11 23:07 
GeneralI can look at it for hours... Pin
Sander Rossel27-May-11 21:48
professionalSander Rossel27-May-11 21:48 
GeneralCongratulations! Pin
Marcelo Ricardo de Oliveira27-May-11 16:04
mvaMarcelo Ricardo de Oliveira27-May-11 16:04 
GeneralRe: Congratulations! Pin
Graham Wilson27-May-11 16:10
Graham Wilson27-May-11 16:10 
GeneralMy vote of 5 Pin
Keith Barrow23-May-11 23:34
professionalKeith Barrow23-May-11 23:34 
GeneralMy vote of 5 Pin
Manfred Rudolf Bihy23-May-11 13:04
professionalManfred Rudolf Bihy23-May-11 13:04 
GeneralGood ! Pin
Wonde Tadesse21-May-11 12:10
professionalWonde Tadesse21-May-11 12:10 

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.