1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Public Class Circulaire : Inherits ProgressBar
Private _MyFont As Font = New Font("Times New Roman", 18, FontStyle.Bold)
Public Property MyFont As Font
Get
Return _MyFont
End Get
Set(value As Font)
_MyFont = value
Me.Invalidate()
End Set
End Property
Private _Color1 As Color = Color.DodgerBlue
Public Property Color1 As Color
Get
Return _Color1
End Get
Set(value As Color)
If value = Color.Transparent OrElse value = _Color1 Then
Return
Else
_Color1 = value
Me.Invalidate()
End If
End Set
End Property
Private _Color2 As Color = Color.Blue
Public Property Color2 As Color
Get
Return _Color2
End Get
Set(value As Color)
If value = Color.Transparent OrElse value = _Color2 Then
Return
Else
_Color2 = value
Me.Invalidate()
End If
End Set
End Property
Private _Color3 As Color = Color.Black
Public Property Color3 As Color
Get
Return _Color3
End Get
Set(value As Color)
If value = Color.Transparent Then
Return
Else
_Color3 = value
Me.Invalidate()
End If
End Set
End Property
Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
Me.Size = New Size(180, 160)
Me.ForeColor = Color.Black
End Sub
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
Using bmp As New Bitmap(rect.Width, rect.Height)
Using b As Graphics = Graphics.FromImage(bmp)
Dim path As GraphicsPath = CirclulairePath(b, rect, _Color1, _Color2)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim HeightH As Integer = CInt((rect.Height / (Maximum - Minimum)) * Value)
e.Graphics.DrawImage(bmp, New Rectangle(rect.X, rect.Height - HeightH, rect.Width, HeightH), New Rectangle(rect.X, rect.Height - HeightH, Math.Min(bmp.Width, rect.Width), Math.Min(bmp.Height, HeightH)), GraphicsUnit.Pixel)
e.Graphics.DrawPath(New Pen(New SolidBrush(_Color3), 2), path)
e.Graphics.DrawString(Value & " %", MyFont, New SolidBrush(Me.ForeColor), rect, New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
End Using
End Using
End Sub
Private Function CirclulairePath(b As Graphics, rect As Rectangle, Color1 As Color, Color2 As Color) As GraphicsPath
Dim p As New GraphicsPath
p.AddEllipse(New Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3))
p.CloseFigure()
b.FillPath(New SolidBrush(Color1), p)
p.AddEllipse(New Rectangle(CInt(rect.Width / 4), CInt(rect.Height / 4), CInt(rect.Width / 2), CInt(rect.Height / 2)))
p.CloseFigure()
b.FillPath(New SolidBrush(Color2), p)
Return p
End Function
End Class |