Public Class MetroProgressbar
Inherits Control
Dim _BorderColor As Color = Color.Black
Property BorderColor As Color
Get
Return _BorderColor
End Get
Set(ByVal value As Color)
_BorderColor = value
Invalidate()
End Set
End Property
Dim _ProgressColor As Color = Color.FromArgb(10, 150, 40)
Property ProgressColor As Color
Get
Return _ProgressColor
End Get
Set(ByVal value As Color)
_ProgressColor = value
Invalidate()
End Set
End Property
Sub New()
SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
DoubleBuffered = True
End Sub
Dim _Val As Integer = 0
Property Value As Integer
Get
Return _Val
End Get
Set(ByVal v As Integer)
If v <= _Max Then _Val = v Else Throw New Exception("The entered value is not valid.")
Invalidate()
End Set
End Property
Dim _Max As Integer = 100
Property Maximum As Integer
Get
Return _Max
End Get
Set(ByVal value As Integer)
If value >= _Val Then _Max = value Else Throw New Exception("The entered value is not valid.")
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim G As Graphics = e.Graphics
Dim Progress As Double = (_Val / _Max) * (Width - 2)
G.Clear(BackColor)
G.FillRectangle(New SolidBrush(Color.FromArgb(20, Color.Black)), New Rectangle(0, 0, Width - 1, Height - 1))
If Progress > 0 Then G.FillRectangle(New SolidBrush(_ProgressColor), New Rectangle(1, 1, CInt(Progress), Height - 2))
G.DrawRectangle(New Pen(_BorderColor), New Rectangle(0, 0, Width - 1, Height - 1))
MyBase.OnPaint(e)
End Sub
End Class ' MetroProgressbar