


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