Click here to Skip to main content
14,879,887 members
Articles / Programming Languages / Visual Basic
Tip/Trick
Posted 1 Dec 2011

Stats

42.3K views
2.3K downloads
22 bookmarked

Glass Style ProgressBar

Rate me:
Please Sign up or sign in to vote.
4.95/5 (17 votes)
26 Apr 2012CPOL1 min read
A Glass style progress bar

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 lots of 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 which inherits all the properties of simple progress bar. I added some extra functionalities in MBProgressBar like Animation, Glow, Highlight, etc. The language used is VB.NET.

Control Properties

Here is the list of properties available in MBProgressBar:

  • Color: This property is used to set the MBProgressBar color.
  • GlowColor: This property is used to set the glow color of MBProgressBar.
  • BackgroundColor: This property is used to set the back color of MBProgressBar.
  • HighlightColor: This property is used to set the highlight color of MBProgressBar.
  • Animation: This property is used to set the animation of 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:

VB.NET
Private Sub GlowAnimation_Paint(ByVal sender As Object, _
           ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
    DrawBackground(e.Graphics)
    DrawBackgroundShadows(e.Graphics)
    DrawBar(e.Graphics)
    DrawBarShadows(e.Graphics)
    DrawHighlight(e.Graphics)
    DrawInnerStroke(e.Graphics)
    DrawGlow(e.Graphics)
    DrawOuterStroke(e.Graphics)
End Sub

Following are some methods which provide a transparent look to MBProgressBar. This method draws the background for MBProgressBar.

VB.NET
Private Sub DrawBackground(ByVal g As Graphics)
    Dim r As Rectangle = Me.ClientRectangle
    r.Width = r.Width - 1
    r.Height = r.Height - 1
    Dim rr As GraphicsPath = RoundRect(r, 2, 2, 2, 2)
    g.FillPath(New SolidBrush(Me.BackgroundColor), rr)
End Sub

This method draws the background shadow for MBProgressBar.

VB.NET
Private Sub DrawBackgroundShadows(ByVal g As Graphics)
    Dim lr As Rectangle = New Rectangle(2, 2, 10, Me.Height - 5)
    Dim lg As LinearGradientBrush = New LinearGradientBrush(lr, _
        Color.FromArgb(30, 0, 0, 0), Color.Transparent, _
        LinearGradientMode.Horizontal)
    lr.X = lr.X - 1
    g.FillRectangle(lg, lr)
    Dim rr As Rectangle = New Rectangle(Me.Width - 12, 2, 10, Me.Height - 5)
    Dim rg As LinearGradientBrush = New LinearGradientBrush(lr, _
        Color.Transparent, Color.FromArgb(20, 0, 0, 0), _
        LinearGradientMode.Horizontal)
    lr.X = lr.X - 1
    g.FillRectangle(rg, rr)
End Sub

This method draws MBProgressBar:

VB.NET
Private Sub DrawBar(ByVal g As Graphics)
    Dim r As Rectangle = New Rectangle(1, 2, Me.Width - 3, Me.Height - 3)
    r.Width = CInt((Value * 1.0F / (100) * Me.Width))
    g.FillRectangle(New SolidBrush(Color()), r)
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

License

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

Share

About the Author

Manoj K Bhoir
Software Developer
India India
It always seems good to hear about me, but the thing I do is I code. I'm Interested in Designing Windows Based Application, Web Applications and building Mobile Applications. Currently restricting it to Android 4.0 applications, building Internet Based Applications using ASP.NET and contributing to bring the student community to a position which will help technology to reach the greatest heights ever. A very Big fan of Microsoft & Android..!!

Comments and Discussions

 
AnswerProblem solved! Pin
User 1327559318-Sep-17 5:45
MemberUser 1327559318-Sep-17 5:45 
GeneralMy vote of 5 Pin
Andre Teunissen11-Dec-12 4:07
MemberAndre Teunissen11-Dec-12 4:07 
GeneralRe: My vote of 5 Pin
Manoj K Bhoir11-Dec-12 17:36
professionalManoj K Bhoir11-Dec-12 17:36 
GeneralMy vote of 5 Pin
MacSpudster30-Apr-12 7:30
professionalMacSpudster30-Apr-12 7:30 
GeneralRe: My vote of 5 Pin
Manoj K Bhoir2-May-12 18:02
professionalManoj K Bhoir2-May-12 18:02 
QuestionPicture? Pin
Dave Cross26-Apr-12 22:17
professionalDave Cross26-Apr-12 22:17 
GeneralReason for my vote of 5 Awesome work. Pin
Jαved6-Dec-11 20:44
professionalJαved6-Dec-11 20:44 
GeneralRe: Thank You! Pin
Manoj K Bhoir7-Dec-11 20:48
professionalManoj K Bhoir7-Dec-11 20:48 
GeneralReason for my vote of 5 Well thought out and ready to use! Pin
gbigden5-Dec-11 23:16
Membergbigden5-Dec-11 23:16 
Reason for my vote of 5
Well thought out and ready to use!
GeneralRe: Thank You! Pin
Manoj K Bhoir7-Dec-11 20:48
professionalManoj K Bhoir7-Dec-11 20:48 
GeneralThank You Deeksha!Now the Download-Link Problem Solved. Pin
Manoj K Bhoir3-Dec-11 0:53
professionalManoj K Bhoir3-Dec-11 0:53 
GeneralYes!I don't know why but it show cirtification error.If you ... Pin
Manoj K Bhoir2-Dec-11 4:52
professionalManoj K Bhoir2-Dec-11 4:52 
GeneralDownload-Link doesn't work!! Pin
AxelM1-Dec-11 21:58
MemberAxelM1-Dec-11 21:58 

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.