1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Class MyProgressBar
Inherits ProgressBar
Public Sub New()
MyBase.New()
Me.SetStyle((ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint), True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim rect As Rectangle = Me.ClientRectangle
Dim g As Graphics = e.Graphics
ProgressBarRenderer.DrawHorizontalBar(g, rect)
rect.Inflate(0, 0)
If (Me.Value > 0) Then
Dim clip As Rectangle = New Rectangle(rect.X, rect.Y, CType(Math.Round(((CType(Me.Value, Single) / Me.Maximum) _
* rect.Width)), Single), rect.Height)
ProgressBarRenderer.DrawHorizontalChunks(g, clip)
End If
Dim text As String = (Value & " %")
Dim f As Font = New Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold)
Dim strSize As SizeF = g.MeasureString(text, f)
Dim location As Point = New Point(CType(((rect.Width / 2) _
- (strSize.Width / 2)), Single), CType(((rect.Height / 2) _
- (strSize.Height / 2)), Single))
g.DrawString(text, f, Brushes.Blue, location)
End Sub
End Class |
Partager