C# Alternative ProgressBar





4.00/5 (17 votes)
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.
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 controlBorderThickness
- The width of the border around the controlCompositingMode
- TheCompositingMode
of the control's GraphicsCompositingQuality
- TheCompositingQuality
of the control's GraphicsErrorLog
- If any errors have occurred (useHasErrors
to check), this will contain information on the errors that have occurredHasErrors
- If any errors have occurred, this will be set to trueInterpolationMode
- TheInterpolationMode
of the control's GraphicsMaximum
- The maximum valueMinimum
- The minimum valueOrientation
- TheOrientation
of the controlPixelOffsetMode
- ThePixelOffsetMode
of the control's GraphicsSmoothingMode
- TheSmoothingMode
of the control's GraphicsTextColor
- The color of the text that is drawn on the controlTextStyle
- Determines what type of text is drawn on the control.None
- No text is shownPercentage
- The percentage is shown. This is calculated via: double p = Convert.ToDouble((100d / maximum) * Value);Text
- The string in theText
property of the control is shown (if the text is not null or all whitespace)Value
- The current Value is shownValueOverMaximum
- The currentValue
andMaximum
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();
}