-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportProgress.vb
52 lines (43 loc) · 1.97 KB
/
ReportProgress.vb
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Drawing.Drawing2D
Public Class ReportProgress
Implements IReportProgress
Sub New(Bar As ToolStripProgressBar)
_ProgressBar = Bar
ProgressBar.Value = 0
End Sub
Private ReadOnly Property ProgressBar As ToolStripProgressBar
Private Shared Sub pbPrecentage(pb As ToolStripProgressBar, Text As String)
Using gr As Graphics = pb.ProgressBar.CreateGraphics()
'Switch to Anti-aliased drawing for better (smoother) graphic results
gr.SmoothingMode = SmoothingMode.AntiAlias
gr.DrawString(Text, SystemFonts.DefaultFont, Brushes.Black, New PointF(pb.Width \ 2 - (gr.MeasureString(Text, SystemFonts.DefaultFont).Width / 2.0F), pb.Height \ 2 - (gr.MeasureString(Text, SystemFonts.DefaultFont).Height / 2.0F)))
End Using
End Sub
Public Sub Clear() Implements IReportProgress.Clear
ProgressBar.Value = 0
End Sub
Public Sub SetTotalItems(TotalItems As Integer) Implements IReportProgress.SetTotalItems
ProgressBar.Visible = True
ProgressBar.Value = 0
ProgressBar.Maximum = TotalItems
End Sub
Public Sub UpdateProgress(Increment As Integer) Implements IReportProgress.UpdateProgress
ProgressBar.Step = Increment
ProgressBar.PerformStep()
ProgressBar.Step = -1
ProgressBar.PerformStep()
ProgressBar.Step = 1
ProgressBar.PerformStep()
ProgressBar.TextImageRelation = TextImageRelation.Overlay
pbPrecentage(ProgressBar, $"{ProgressBar.Value:N0} of {ProgressBar.Maximum:N0}")
If ProgressBar.Value >= ProgressBar.Maximum Then
ProgressBar.Visible = False
End If
If ProgressBar.Value Mod 100 = 0 Then
Application.DoEvents()
End If
End Sub
End Class