0

Trying to learn how to build progress bars, I looked over a few examples and tried to build one to add to my GUI. Right now I just want to get it to loop through and increase to 98% then fall back down to a random spot. Using pieces from another post Powershell Progress Bar in Windows Forms I tried to put a loop in, its not working though.

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

$form_main = New-Object System.Windows.Forms.Form
$form_main.Width = 300
$form_main.Height = 100
$form_main.Text = 'ProgressBar demo'

$progressBar1 = New-Object System.Windows.Forms.ProgressBar
$progressBar1.Location = new-object System.Drawing.Size(10,10)
$progressBar1.Size = new-object System.Drawing.Size(265,20)
$form_main.Controls.Add($progressBar1)

$Counter = 0

$progressBar1.Value = $Counter
$progressBar1.Step = 1
$progressBar1.Name = 'progressBar1'
$progressBar1.Maximum = 100

$Num = Get-Random -Minimum 50 -Maximum 90

While ($Counter -lt 100) {
    $progressBar1.PerformStep()
    }

if ($Counter -gt 98) {$Counter = $Counter -= $Num}



$form_main.ShowDialog() | Out-Null

Let me know where I am going wrong.

Aoxx
  • 55
  • 1
  • 13
  • If you want to do something concurrently during progress bar updates, you will need to make it event driven by using e.g. a timer (as in the example you refer to) otherwise the progress bar won't update as long as your script is running. – iRon Sep 06 '19 at 20:17
  • I am not understanding how to do that – Aoxx Sep 06 '19 at 20:19
  • https://foxdeploy.com/2016/05/17/part-v-powershell-guis-responsive-apps-with-progress-bars/ – Jacob Colvin Sep 06 '19 at 20:53

0 Answers0