voici comment réaliser un progressbarFleches.
Vous pouvez choisir droite ou gauche dans Arrow et aussi dans changer de couleur dans colorArrow et Colorfill.
voici ma classes :
Imports System.Drawing.Drawing2D
Public Class ProgressbarFleches : Inherits ProgressBar
Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
Me._arrow = Arrows.Right
Me._ColorArrow = Color.White
Me._ColorFill = Color.Red
Me.Size = New Size(300, 100)
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 _ColorArrow As Color
Public Property ColorArrow As Color
Get
Return _ColorArrow
End Get
Set(value As Color)
If value = Color.Transparent Then
Return
Else
_ColorArrow = value
MyBase.Invalidate()
End If
End Set
End Property
Private _arrow As Arrows
Public Property Arrow() As Arrows
Get
Return _arrow
End Get
Set(ByVal value As Arrows)
_arrow = value
MyBase.Invalidate()
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim path As New GraphicsPath
If _arrow = Arrows.Left Then
drawLeftArrow(path)
ElseIf _arrow = Arrows.Right Then
drawRightArrow(path)
End If
e.Graphics.FillPath(New SolidBrush(_ColorArrow), path)
Dim r As Region = New Region(path)
Dim rectF As RectangleF = r.GetBounds(e.Graphics)
Dim lngth As Integer = CInt((rectF.Width / (Maximum - Minimum)) * Value)
If lngth = 0 Then Return
Dim intersectRect As RectangleF = New RectangleF(rectF.X, rectF.Y + 1, lngth, rectF.Height)
r.Intersect(intersectRect)
e.Graphics.FillRegion(New SolidBrush(_ColorFill), r)
End Sub
Enum Arrows
Left
Right
End Enum
Private Sub drawLeftArrow(path As GraphicsPath)
Dim pts() As Point = { _
New Point(CInt(Me.Width / 2 + (Me.Width - 2) / 2), CInt(Me.Height / 2 + Me.Height / 4)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 + Me.Height / 4)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 + Me.Height / 2)), _
New Point(CInt(Me.Width / 2 - Me.Width / 2), CInt(Me.Height / 2)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 - Me.Height / 2)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 - Me.Height / 4)), _
New Point(CInt(Me.Width / 2 + (Me.Width - 2) / 2), CInt(Me.Height / 2 - Me.Height / 4)) _
}
path.AddPolygon(pts)
End Sub
Private Sub drawRightArrow(path As GraphicsPath)
Dim pts() As Point = { _
New Point(CInt(Me.Width / 2 - (Me.Width - 2) / 2), CInt(Me.Height / 2 - Me.Height / 4)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 - Me.Height / 4)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 - Me.Height / 2)), _
New Point(CInt(Me.Width / 2 + Me.Width / 2), CInt(Me.Height / 2)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 + Me.Height / 2)), _
New Point(CInt(Me.Width / 2), CInt(Me.Height / 2 + Me.Height / 4)), _
New Point(CInt(Me.Width / 2 - (Me.Width - 2) / 2), CInt(Me.Height / 2 + Me.Height / 4)) _
}
path.AddPolygon(pts)
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire