Glass Style ProgressBar For Windows Applications

Introduction

Why another Progressbar? The standard ProgressBar is too limited in functionality and I couldn't find a custom control written that did all that I wanted. This is a User Control with many properties and versatility. It is simple to use, just drop it on the form, adjust the design time properties and use it like the normal ProgressBar.

Background

MBProgressBar is a simple progress bar that inherits all the properties of a simple progress bar. I added some extra functionalities in MBProgressBar like Animation, Glow, Highlight and so on. The language used is VB.NET.

Control Properties

Here is the list of properties available in MBProgressBar:

  • Color: This property sets the MBProgressBar color.
  • GlowColor: This property sets the glow color of the MBProgressBar.
  • BackgroundColor: This property sets the back color of the MBProgressBar.
  • HighlightColor: This property sets the highlight color of the MBProgressBar.
  • Animation: This property sets the animation of the MBProgressBar.

Code

 

The concept for this Progressbar came from the Vista "Progress Bar" or Windows 7 “Progress Bar”. I organized my paint event into layers like this:

  1. Private Sub GlowAnimation_Paint(ByVal sender As Object, _  
  2.            ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint  
  3.     e.Graphics.SmoothingMode = SmoothingMode.AntiAlias  
  4.     e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic  
  5.     DrawBackground(e.Graphics)  
  6.     DrawBackgroundShadows(e.Graphics)  
  7.     DrawBar(e.Graphics)  
  8.     DrawBarShadows(e.Graphics)  
  9.     DrawHighlight(e.Graphics)  
  10.     DrawInnerStroke(e.Graphics)  
  11.     DrawGlow(e.Graphics)  
  12.     DrawOuterStroke(e.Graphics)  
  13. End Sub 
The following are some methods that provide a transparent look to MBProgressBar. This method draws the background for the MBProgressBar.
  1. Private Sub DrawBackground(ByVal g As Graphics)  
  2.     Dim r As Rectangle = Me.ClientRectangle  
  3.     r.Width = r.Width - 1  
  4.     r.Height = r.Height - 1  
  5.     Dim rr As GraphicsPath = RoundRect(r, 2, 2, 2, 2)  
  6.     g.FillPath(New SolidBrush(Me.BackgroundColor), rr)  
  7. End Sub 
This method draws the background shadow for the MBProgressBar:
  1. Private Sub DrawBackgroundShadows(ByVal g As Graphics)  
  2.     Dim lr As Rectangle = New Rectangle(2, 2, 10, Me.Height - 5)  
  3.     Dim lg As LinearGradientBrush = New LinearGradientBrush(lr, _  
  4.         Color.FromArgb(30, 0, 0, 0), Color.Transparent, _  
  5.         LinearGradientMode.Horizontal)  
  6.     lr.X = lr.X - 1  
  7.     g.FillRectangle(lg, lr)  
  8.     Dim rr As Rectangle = New Rectangle(Me.Width - 12, 2, 10, Me.Height - 5)  
  9.     Dim rg As LinearGradientBrush = New LinearGradientBrush(lr, _  
  10.         Color.Transparent, Color.FromArgb(20, 0, 0, 0), _  
  11.         LinearGradientMode.Horizontal)  
  12.     lr.X = lr.X - 1  
  13.     g.FillRectangle(rg, rr)  
  14. End Sub 
This method draws the MBProgressBar.
  1. Private Sub DrawBar(ByVal g As Graphics)  
  2.     Dim r As Rectangle = New Rectangle(1, 2, Me.Width - 3, Me.Height - 3)  
  3.     r.Width = CInt((Value * 1.0F / (100) * Me.Width))  
  4.     g.FillRectangle(New SolidBrush(Color()), r)  
  5. End Sub 

Using the Code

 

It is very easy to use the MBProgressBar in your application. Just add the reference of the provided DLL to your application and just drag and drop.

History

  • MBProgressBar Version 1.0

Up Next
    Ebook Download
    View all
    Learn
    View all