QuestionHelpCircular Progress Bar in Visual Basic 2010

Posts 13 of 3 · Page 1 of 1
Circular Progress Bar in Visual Basic 2010
'Sup.

I've been looking around the web and haven't been able to locate a reasonably understandable tutorial on creating a circular progress bar in Visual Basic 2010, so I came here.

I don't know very much VB.net, and no C or C++.

I was hoping to find something that looks like this:



It doesn't necessarily need a percentage, nor does it only need to go around once. It could be something like this that just keeps moving:



Thanks!
DotNetBar has a progress bar very similar.



Customizable styles ofc. Don't bother paying for the DotNetBar (If you have money, most certainly do as it's an excellent piece of software.)
Read about creating custom controls and draw it



 
Control
Code:
Imports System.Drawing.Drawing2D

Class CPB
    Inherits Control

    Public Sub New()
        Width = 100
        Height = 100
        Thickness = 10
    End Sub

    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 _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 _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

    Private G As Graphics
    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
    End Sub

    Private SZ1 As SizeF
    Private PT1 As PointF

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        Using B As New Bitmap(Width, Height)
            Using G As Graphics = Graphics.FromImage(B)
                G.SmoothingMode = SmoothingMode.HighQuality

                G.Clear(BackColor)

                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

                Using T As New LinearGradientBrush(ClientRectangle, Color.White, Color.Gray, LinearGradientMode.Vertical)
                    Using P As New Pen(T, Thickness)

                                          'Remove the spaces ofc v (Round) :F
                        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

                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

                Text = CStr(CInt((100 / _Maximum) * _Value)) & "%"
                SZ1 = G.MeasureString(Text, Font)
                PT1 = New PointF(Width \ 2 - SZ1.Width / 2, Height \ 2 - SZ1.Height / 2)

                Dim S As SizeF = G.MeasureString(CStr(CInt((100 / _Maximum) * _Value)), Font)
                G.DrawString(Text, Font, Brushes.White, PT1)

                G.DrawEllipse(Pens.Black, 0, 0, Width - 1, Height - 1)

                G.DrawEllipse(Pens.Black, Thickness, Thickness, Width - Thickness * 2 - 1, Height - Thickness * 2 - 1)

                e.Graphics.DrawImage(B, 0, 0)
            End Using
        End Using
    End Sub

End Class
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?