Rechercher dans ce blog

mercredi 29 décembre 2021

Progressbar element

 Voici comment realiser un progressbar élément.

vous pouvez choisir les deux couleurs.

ma classe :

Public Class ProgressbarElement : Inherits ProgressBar

    Dim _color As Color
    Public Property Color1 As Color
        Get
            Return _color
        End Get
        Set(value As Color)
            If value = _color2 Then
                Throw New ArgumentException("la couleur 1 ne doit pas la même avec la couleur 2")
            Else
                _color = value
                Me.Invalidate()
            End If
        End Set
    End Property

    Dim _color2 As Color
    Public Property Color2 As Color
        Get
            Return _color2
        End Get
        Set(value As Color)
            If value = _color Then
                Throw New ArgumentException("la couleur 2 ne doit pas la même avec la couleur 1")
            Else
                _color2 = value
                Me.Invalidate()
            End If
        End Set
    End Property

    Public Sub New()
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
        Me.Size = New Size(250, 23)
        DoubleBuffered = True
        Me._color = Color.White
        Me._color2 = Color.FromArgb(93,179,246)
    End Sub

    Protected Overrides Sub OnResize(ByVal e As EventArgs)
        MyBase.OnResize(e)
        If Me.Width < 200 Then
            Me.Width = 200
        ElseIf Me.Height <> 23 Then
            Height = 23
        End If
    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
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        Dim ProgressWidth As Integer = CInt((Me.Width / (Me.Maximum - Me.Minimum)) * Me.Value)
        e.Graphics.FillRectangle(New SolidBrush(_color), New Rectangle(0, 0, ProgressWidth, rect.Height))
        e.Graphics.SetClip(New Rectangle(0, 0, ProgressWidth, rect.Height))
        For i = 0 To ProgressWidth Step 30
            e.Graphics.DrawLine(New Pen(New SolidBrush(_color2), 15), New Point(CInt(i - 15), -6), New Point(CInt(i + 6), Me.Height + 10))
        Next
        e.Graphics.ResetClip()
    End Sub
End Class

Aucun commentaire:

Enregistrer un commentaire