11param (
22 [string ]$Name = " " ,
3- [string ]$Text = " "
3+ [string ]$Text = " " ,
4+ [int ]$Progress = 0
45)
56
6- [Windows.Forms.Application ]::EnableVisualStyles()
7-
87Add-Type - AssemblyName System.Windows.Forms
98Add-Type - AssemblyName System.Drawing
109
10+ [Windows.Forms.Application ]::EnableVisualStyles()
11+
1112$form = New-Object Windows.Forms.Form
1213$form.Text = $Name
13- $form.Size = New-Object Drawing.Size(400 , 90 )
14+ $form.Size = New-Object Drawing.Size(400 , 120 )
1415$form.StartPosition = " CenterScreen"
1516$form.FormBorderStyle = " FixedDialog"
1617$form.MaximizeBox = $false
@@ -19,10 +20,40 @@ $form.ControlBox = $false
1920$form.TopMost = $true
2021
2122$label = New-Object Windows.Forms.Label
22- $label.Text = $Text
23- $label.Location = New-Object Drawing.Point(20 , 20 )
23+ $label.Text = " $Text ( $Progress %) "
24+ $label.Location = New-Object Drawing.Point(20 , 15 )
2425$label.AutoSize = $true
2526$label.Font = New-Object System.Drawing.Font(' Microsoft JhengHei' , 10 )
27+
28+ $progressBar = New-Object Windows.Forms.ProgressBar
29+ $progressBar.Location = New-Object Drawing.Point(20 , 50 )
30+ $progressBar.Size = New-Object Drawing.Size(340 , 20 )
31+ $progressBar.Minimum = 0
32+ $progressBar.Maximum = 100
33+ $progressBar.Value = $Progress
34+
2635$form.Controls.Add ($label )
36+ $form.Controls.Add ($progressBar )
37+
38+ $timer = New-Object Windows.Forms.Timer
39+ $timer.Interval = 100
40+
41+ $timer.Add_Tick ({
42+ while ([Console ]::In .Peek() -ne -1 ) {
43+ $line = [Console ]::In .ReadLine()
44+ if ($line -ne $null ) {
45+ $value = [int ]$line
46+ if ($value -ge 0 -and $value -le 100 ) {
47+ $progressBar.Value = $value
48+ $label.Text = " $Text ($value %)"
49+ }
50+ }
51+ }
52+ })
53+
54+ $timer.Start ()
55+
56+ $form.Add_Shown ({ $form.Activate () })
57+ [void ]$form.Show ()
2758
28- $form .ShowDialog ( )
59+ [ Windows.Forms.Application ]::Run( $form )
0 commit comments