Click here to Skip to main content
14,494,237 members

C# Alternative ProgressBar

Rate this:
3.97 (17 votes)
Please Sign up or sign in to vote.
3.97 (17 votes)
3 Sep 2013CPOL
An alternative ProgressBar for C# with extra functionality

 

Introduction   

This is an alternative ProgressBar for C# that adds an Orientation option as well as the ability to draw text on the control.

Image 1

 

After having ran into a scenario where I needed a ProgressBar with a vertical orientation, I was disappointed to find that Microsoft's default ProgressBar did not support changing the orientation. So, I decided to create a simple drop-in replacement that added a few extra features.  

The control is pretty basic and it works the same as the default ProgressBar.

For an example of this control's usage, please see the TestApp that is in this project's source zip file.

Using the Code  

Properties 

  • BorderColor - The color of the border around the control
  • BorderThickness - The width of the border around the control
  • CompositingMode - The CompositingMode of the control's Graphics  
  • CompositingQuality - The CompositingQuality of the control's Graphics
  • ErrorLog - If any errors have occurred (use HasErrors to check), this will contain information on the errors that have occurred     
  • HasErrors - If any errors have occurred, this will be set to true
  • InterpolationMode - The InterpolationMode of the control's Graphics 
  • Maximum - The maximum value  
  • Minimum - The minimum value  
  • Orientation - The Orientation of the control  
  • PixelOffsetMode - The PixelOffsetMode of the control's Graphics 
  • SmoothingMode - The SmoothingMode of the control's Graphics
  • TextColor - The color of the text that is drawn on the control
  • TextStyle - Determines what type of text is drawn on the control.
    • None - No text is shown   
    • Percentage - The percentage is shown. This is calculated via: double p = Convert.ToDouble((100d / maximum) * Value);  
    • Text - The string in the Text property of the control is shown (if the text is not null or all whitespace) 
    • Value - The current Value is shown 
    • ValueOverMaximum - The current Value and Maximum is shown via: String.Format("{0}/{1}", currentValue, maximum); 
  • Value - The current value   

Methods  

  • ClearErrors() -   Clears the ErrorLog string property and sets the HasErrors property to  

Events 

  • ValueChanged(object sender, ValueChangedEventArgs e) - Occurs when the Value of the ProgressBar has changed  

Example 

private void Form1_Load(object sender, EventArgs e)
{
	basicProgressBar1.Maximum = 100;
	basicProgressBar1.Minimum = 0;
	basicProgressBar1.Value = 0;    
}
private void basicProgressBar1_ValueChanged(object sender, ProgressBars.Basic.ValueChangedEventArgs e)
{
    txtValueChanged.Text = e.Value.ToString();
}

License

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

Share

About the Author

blitzkrieged
United States United States
No Biography provided

Comments and Discussions

 
QuestionThanks Pin
Arethrid18-Nov-15 1:54
MemberArethrid18-Nov-15 1:54 
QuestionSource code files are missing Pin
Tridip Bhattacharjee2-Sep-13 20:53
professionalTridip Bhattacharjee2-Sep-13 20:53 
AnswerRe: Source code files are missing Pin
blitzkrieged2-Sep-13 21:02
Memberblitzkrieged2-Sep-13 21:02 
GeneralMy vote of 1 Pin
Sperneder Patrick2-Sep-13 1:51
professionalSperneder Patrick2-Sep-13 1:51 
GeneralMy vote of 2 Pin
Sacha Barber2-Sep-13 0:06
MemberSacha Barber2-Sep-13 0:06 
GeneralRe: My vote of 2 Pin
Fredrik Bornander2-Sep-13 4:29
professionalFredrik Bornander2-Sep-13 4:29 
GeneralRe: My vote of 2 Pin
blitzkrieged2-Sep-13 12:23
Memberblitzkrieged2-Sep-13 12:23 
GeneralRe: My vote of 2 Pin
blitzkrieged2-Sep-13 12:29
Memberblitzkrieged2-Sep-13 12:29 
GeneralMy vote of 1 Pin
taras_b31-Aug-13 3:54
Membertaras_b31-Aug-13 3:54 
GeneralRe: My vote of 1 Pin
blitzkrieged31-Aug-13 11:54
Memberblitzkrieged31-Aug-13 11:54 
GeneralUp-voting my "vote of 1" Pin
taras_b31-Aug-13 14:22
Membertaras_b31-Aug-13 14:22 
GeneralRe: Up-voting my "vote of 1" Pin
blitzkrieged31-Aug-13 14:32
Memberblitzkrieged31-Aug-13 14:32 
GeneralMy vote of 5 Pin
Gun Gun Febrianza30-Aug-13 20:15
Member Gun Gun Febrianza30-Aug-13 20:15 
GeneralRe: My vote of 5 Pin
blitzkrieged31-Aug-13 11:54
Memberblitzkrieged31-Aug-13 11:54 

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.

Tip/Trick
Posted 30 Aug 2013

Stats

40.8K views
4.6K downloads
23 bookmarked