Voici comment réaliser un progressbar avec multiple carrer.
vous pouvez choisir nombre carrer 1 jusqu"a 10 et choisir épaisseur du carrer 1 jusqu’à 5.
ma classes :
Public Class ProgressbarCarrer : Inherits ProgressBar
Private _progressbarColor As Color = Color.Lime
Public Property ProgressbarColor As Color
Get
Return _progressbarColor
End Get
Set(value As Color)
If value = _CarrerColor Then
Throw New ArgumentException("la couleur progressbar ne peut pas étre la méme couleur progressbar carrer.")
Return
Else
_progressbarColor = value
Me.Invalidate()
End If
End Set
End Property
Private _CarrerColor As Color = Color.Black
Public Property CarrerColor As Color
Get
Return _CarrerColor
End Get
Set(value As Color)
If value = _progressbarColor Then
Throw New ArgumentException("La couleur progressbar carrer ne peut pas étre la méme de la couleur progressbar.")
Return
Else
_CarrerColor = value
Me.Invalidate()
End If
End Set
End Property
Private _Epaisseur As Integer = 5
Public Property ProgressbarEpaisseur As Integer
Get
Return _Epaisseur
End Get
Set(value As Integer)
If value < 1 OrElse value > 5 Then
Throw New ArgumentException("la valeur doit être compris entre 1 jusqu'à 5")
Return
Else
_Epaisseur = value
Me.Invalidate()
End If
End Set
End Property
Private _ProgressbarCarrer As Integer = 10
Public Property ProgressbarCarrer() As Integer
Get
Return _ProgressbarCarrer
End Get
Set(value As Integer)
If value < 1 OrElse value > 10 Then
Throw New ArgumentException("la valeur doit être compris entre 1 jusqu'à 10")
Return
Else
_ProgressbarCarrer = value
Me.Invalidate()
End If
End Set
End Property
Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
Me.Size = New Size(350, 23)
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
If ProgressBarRenderer.IsSupported Then
ProgressBarRenderer.DrawHorizontalBar(e.Graphics, rect)
End If
rect.Width = CInt((Me.Width / (Me.Maximum - Me.Minimum) * Me.Value))
If rect.Width < 0 Then Return
Using b As New SolidBrush(_progressbarColor)
e.Graphics.FillRectangle(b, rect)
End Using
For i As Integer = 1 To _ProgressbarCarrer
Dim widthValue As Integer = Me.Width / _ProgressbarCarrer
e.Graphics.DrawRectangle(New Pen(_CarrerColor, _Epaisseur), New Rectangle(0, 0, rect.Left - 1 + (i * widthValue), rect.Height - 1))
Next
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire