Voici comment réaliser un progressbartext.
ma classes :
Imports System.Drawing.Drawing2D
Public Class ProgressbarText : Inherits ProgressBar
Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
Me._Text = "Chargement..."
Me._MyFont = New Font("Microsoft Sans Serif", 48, FontStyle.Regular)
Me.Size = New Size(530, 85)
Me._ColorText = Color.Blue
Me._CBorder = 2
Me._ColorBorder = Color.Black
Me._ColorFill = Color.White
End Sub
Public _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
MyBase.Invalidate()
End If
End Set
End Property
Public _ColorBorder As Color
Public Property ColorBorder As Color
Get
Return _ColorBorder
End Get
Set(value As Color)
If value = Color.Transparent Then
Return
Else
_ColorBorder = value
MyBase.Invalidate()
End If
End Set
End Property
Public _CBorder As Integer
Public Property CBorder As Integer
Get
Return _CBorder
End Get
Set(value As Integer)
If value = 0 OrElse value > 4 Then
Return
Else
_CBorder = value
MyBase.Invalidate()
End If
End Set
End Property
Public _ColorText As Color
Public Property ColorText As Color
Get
Return _ColorText
End Get
Set(value As Color)
If value = Color.Transparent Then
Return
Else
_ColorText = value
MyBase.Invalidate()
End If
End Set
End Property
Public _MyFont As Font
Public Property MyFont As Font
Get
Return _MyFont
End Get
Set(value As Font)
_MyFont = value
MyBase.Invalidate()
End Set
End Property
Public _Text As String
Public Property MyText() As String
Get
Return _Text
End Get
Set(value As String)
_Text = value
MyBase.Invalidate()
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 rect As New Rectangle(0, 0, Me.Width, Me.Height)
Dim sf As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
Dim path As New GraphicsPath()
path.AddString(_Text, _MyFont.FontFamily, _MyFont.Style, rect.Height - 15 - _MyFont.Size / 72, rect, sf)
e.Graphics.DrawPath(New Pen(_ColorBorder, _CBorder), path)
e.Graphics.FillPath(New SolidBrush(_ColorFill), 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, lngth, rectF.Height)
r.Intersect(intersectRect)
e.Graphics.FillRegion(New SolidBrush(_ColorText), r)
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire