Voici comment realiser un progressbar Line.
vous pouvez choisir la couleur du Line et espace entre et choisir type border.
ma classe :
Public Class ProgressbarLine : Inherits ProgressBar
Private _BorderStyle As BorderStyle
Public Property ProgressBarBoderStyle As BorderStyle
Get
Return Me._BorderStyle
End Get
Set(ByVal value As BorderStyle)
If (Me._BorderStyle <> value) Then
Me._BorderStyle = value
MyBase.Invalidate()
End If
End Set
End Property
Private _SpaceText As Integer
Public Property SpaceText As Integer
Get
Return _SpaceText
End Get
Set(value As Integer)
_SpaceText = value
MyBase.Invalidate()
End Set
End Property
Private _MyFont As Font
Public Property MyFont As Font
Get
Return _MyFont
End Get
Set(value As Font)
_MyFont = value
Me.Invalidate()
End Set
End Property
Public _ColorLine As Color
Public Property ColorLine As Color
Get
Return _ColorLine
End Get
Set(value As Color)
_ColorLine = value
MyBase.Invalidate()
End Set
End Property
Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
Me.ColorLine = Color.Yellow
Me._MyFont = New Font("Times New Roman", 12, FontStyle.Regular)
Me.Size = New Size(300, 23)
Me._SpaceText = 50
Me._BorderStyle = BorderStyle.None
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
DrawPrgressBarBorder(e.Graphics)
Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
For x As Integer = 0 To rect.Width Step 4
e.Graphics.DrawLine(New Pen(_ColorLine, 2), x + _SpaceText, rect.Y, x + _SpaceText, rect.Height - 1)
Next
Using sf As New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center}
e.Graphics.DrawString(Value & " %", _MyFont, New SolidBrush(_ColorLine), Me.ClientRectangle, sf)
End Using
Dim progressWidht As Integer = CInt(((rect.Left + (rect.Width - _SpaceText + 1)) / (Maximum - Minimum)) * Value)
e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(150, Color.Black)), New Rectangle((rect.X + _SpaceText - 1) + progressWidht, rect.Y, rect.Width, rect.Height))
End Sub
Private Sub DrawPrgressBarBorder(g As Graphics)
If (Me._BorderStyle = BorderStyle.Single) Then
ControlPaint.DrawBorder(g, MyBase.ClientRectangle, Color.Black, ButtonBorderStyle.Solid)
ElseIf (Me._BorderStyle = BorderStyle.Flat) Then
ControlPaint.DrawBorder3D(g, MyBase.ClientRectangle, Border3DStyle.Flat)
ElseIf (Me._BorderStyle = BorderStyle.Sunken) Then
ControlPaint.DrawBorder3D(g, MyBase.ClientRectangle, Border3DStyle.Sunken)
ElseIf (Me._BorderStyle = BorderStyle.SunkenInner) Then
ControlPaint.DrawBorder3D(g, MyBase.ClientRectangle, Border3DStyle.SunkenInner)
ElseIf (Me._BorderStyle = BorderStyle.SunkenOut) Then
ControlPaint.DrawBorder3D(g, MyBase.ClientRectangle, Border3DStyle.SunkenOuter)
End If
End Sub
Public Enum BorderStyle
Flat = 0
SunkenOut = 1
SunkenInner = 2
Sunken = 3
[Single] = 4
None = 5
End Enum
End Class
Aucun commentaire:
Enregistrer un commentaire