Rechercher dans ce blog

mercredi 29 décembre 2021

ProgressbarPolygons

 Voici un comment réaliser un progressbar avec polygon.


vous pouvez choisir la couleur dans color1 et fillcolor.

ma classe :

Imports System.Drawing.Drawing2D

Public Class ProgressbarPolygons : Inherits ProgressBar

    Public Sub New()
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
        Me._Color1 = Color.Blue
        Me.Size = New Size(350, 35)
        Me._ColorFill = Color.FromArgb(230, 230, 230)
    End Sub

    Private _ColorFill As Color
    Public Property ColorFill As Color
        Get
            Return _ColorFill
        End Get
        Set(value As Color)
            If value = Color.Transparent Then
                Return
            Else
                _ColorFill = value
                Me.Invalidate()
            End If
        End Set
    End Property

    Private _Color1 As Color
    Public Property Color1 As Color
        Get
            Return _Color1
        End Get
        Set(value As Color)
            If value = Color.Transparent Then
                Return
            Else
                _Color1 = value
                Me.Invalidate()
            End If
        End Set
    End Property

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
        Dim g As Graphics = e.Graphics
        Dim Angle As Integer = 36
        Dim x As Integer = e.ClipRectangle.X
        Dim y As Integer = e.ClipRectangle.Y
        Dim width As Integer = Me.Width - Angle - 1
        Dim height As Integer = Me.Height - 1
        Dim points As New List(Of Point) From {New Point(x, y), New Point(x, y + height), New Point(x + width, y + height), New Point(x + Angle + width, y)}
        g.FillPolygon(New SolidBrush(_ColorFill), points.ToArray)
        g.DrawPolygon(Pens.Black, points.ToArray)
        Dim valueLength As Integer = CInt((width / Maximum - Minimum) * Value)
        If valueLength = 0 Then Return
        g.FillPolygon(New SolidBrush(_Color1), GetPoints(x, y, width, height, Angle, valueLength))
    End Sub

    Private Function GetPoints(x As Integer, y As Integer, width As Integer, height As Integer, angle As Integer, Length As Integer) As Point()
        Dim pts As New List(Of Point)
        pts.Add(New Point(x, y))
        pts.Add(New Point(x, y + height))
        pts.Add(New Point(x + Length, y + height))
        pts.Add(New Point(x + Length + angle, y))
        Return pts.ToArray
    End Function
End Class

Aucun commentaire:

Enregistrer un commentaire