Radial/Circular Progressbar Control For VB.NET


hey guys , after you may have seen this post circular progressbar but it's just drawing graphics on the form , now i have got something that's really a progressbar control :) so you can see a GIF image that i have recorded to show you all how the progressbar works . this is not a DLL this is just a class so when you are on a project add a class and put the codes you see below and build your program and you will see this in the toolbox



properties vb.net

so just drag and drop it into your form


now you can just do your coding works and other things,

heres the code :

'Creator: Aeonhack
'Release: January 6th, 2010
'Version: 1.0.0.0
'Website: www.elitevs.net
'Colors modified by Zer0, original was green and is lost.

Imports System.Drawing.Drawing2D
Public Class RadialBar : Inherits Control

    Sub New()
        Size = New Size(150, 150)
        Font = New Font("Verdana", 14.0!)
    End Sub

    'Notice in our properties, in the set routine we call 'Invalidate()' this will cause the
    'control to redraw anytime the values are changed.

    Private _Value As Long
    Public Property Value() As Long
        Get
            Return _Value
        End Get
        Set(ByVal v As Long)
            If v > _Maximum Then v = _Maximum
            _Value = v : Invalidate()
        End Set
    End Property

    Private _Maximum As Long = 100
    Public Property Maximum() As Long
        Get
            Return _Maximum
        End Get
        Set(ByVal v As Long)
            If v < 1 Then v = 1
            _Maximum = v : Invalidate()
        End Set
    End Property

    Private _Thickness As Integer = 20
    Public Property Thickness() As Integer
        Get
            Return _Thickness
        End Get
        Set(ByVal v As Integer)
            _Thickness = v : Invalidate()
        End Set
    End Property

    'Handle PaintBackground to prevent flicker
    Protected Overrides Sub OnPaintBackground(ByVal p As PaintEventArgs)
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        MyBase.OnPaint(e)

        'Create image buffer
        Using B As New Bitmap(Width, Height)
            Using G As Graphics = Graphics.FromImage(B)
                'Enable anti-aliasing to prevent rough edges
                G.SmoothingMode = SmoothingMode.HighQuality

                'Fill background color
                G.Clear(BackColor)

                'Draw progress background
                Using T As New LinearGradientBrush(ClientRectangle, Color.White, Color.White, LinearGradientMode.Vertical)
                    Using P As New Pen(T, Thickness)
                        G.DrawArc(P, CInt(Thickness / 2), CInt(Thickness / 2), Width - Thickness - 1, Height - Thickness - 1, 0, 360)
                    End Using
                End Using

                'Draw progress
                Using T As New LinearGradientBrush(ClientRectangle, Color.White, Color.Gray, LinearGradientMode.Vertical)
                    Using P As New Pen(T, Thickness)
                        P.StartCap = LineCap.Round : P.EndCap = LineCap.Round
                        G.DrawArc(P, CInt(Thickness / 2), CInt(Thickness / 2), Width - Thickness - 1, Height - Thickness - 1, -90, CInt((360 / _Maximum) * _Value))
                    End Using
                End Using

                'Draw center
                Using T As New LinearGradientBrush(ClientRectangle, Color.Gray, Color.Black, LinearGradientMode.Vertical)
                    G.FillEllipse(T, Thickness, Thickness, Width - Thickness * 2 - 1, Height - Thickness * 2 - 1)
                End Using

                'Draw progress string
                Dim S As SizeF = G.MeasureString(CStr(CInt((100 / _Maximum) * _Value)), Font)
                G.DrawString(CStr(CInt((100 / _Maximum) * _Value)), Font, Brushes.White, CInt(Width / 2 - S.Width / 2), CInt(Height / 2 - S.Height / 2))

                'Draw outter border
                G.DrawEllipse(Pens.Black, 0, 0, Width - 1, Height - 1)

                'Draw inner border
                G.DrawEllipse(Pens.Black, Thickness, Thickness, Width - Thickness * 2 - 1, Height - Thickness * 2 - 1)

                'Output the buffered image
                e.Graphics.DrawImage(B, 0, 0)
            End Using
        End Using

    End Sub

End Class

have fun with your new circular progress bar

8 comments

nice job :)

Reply

Hi,their I would love for you to teach me how write/design from scratch a complete real looking Radial Gauge in vb.net gdi+ ,i can't find any tutorials nor books specific on this design.I would love to learn properly from start to finish writing the code to make my own ActiviX.dll or Just a class project type controls for my own learning and projects?
Thank you

Reply

Or you could write to my email pavlovski_dushko@yahoo.com.au or compile a pdf or doc for me to learn or what ever way you can help me I will be most grateful..Thank you

Reply

Hi,

Maybe this what you're looking for : http://www.codeproject.com/Articles/20341/Aqua-Gauge

Thanks

Reply

Hi their I know about the aqua-gauge control site and other sites, but none of them explain how properly from the start in VB.NET that's why i'm asking for your HELP here on how to from scratch?
PLEASE HELP

Reply

Hi,

I don't have any experience in it but I'll let you know if I could it properly(I have your email)

Thank you

Reply

It is not working for me

Reply

Works Perfectly. Thanks!!!

Reply

Post a Comment

Note: Only a member of this blog may post a comment.