Procress Bar Function never 100%

by mk.maddin at 2013-02-08 07:16:00

Hey,

I’ve written two functions. One creates a ProgesBarForm and shows it. The second edites properties in this ProgresBarForm.
My problem is that the progess bar on this form never comes up to 100 Precent.

In the following my script with some "test" calls on the functions - i recommend coyping the text into PowerGUI script editor.

Thank you for your help in advance

mk.maddin

#region ProgBar-Aviable

Function ProgBar-Aviable
{
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
$global:FormtPB = New-Object System.Windows.Forms.Form
$global:FormtPB_LBL = New-Object System.Windows.Forms.Label
$global:ProgBar = New-Object System.Windows.Forms.ProgressBar
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 68
$System_Drawing_Size.Width = 582
$FormtPB.ClientSize = $System_Drawing_Size
$FormtPB.DataBindings.DefaultDataSourceUpdateMode = 0
$FormtPB.Name = "FormtPB"
$FormtPB.Text = "FormtPB.Text"

$FormtPB_LBL.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 9
$FormtPB_LBL.Location = $System_Drawing_Point
$FormtPB_LBL.Name = "FormtPB_LBL"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 17
$System_Drawing_Size.Width = 558
$FormtPB_LBL.Size = $System_Drawing_Size
$FormtPB_LBL.TabIndex = 1
$FormtPB_LBL.Text = "FormtPB_LBL.Text"

$FormtPB.Controls.Add($global:FormtPB_LBL)

$ProgBar.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 29
$ProgBar.Location = $System_Drawing_Point
$ProgBar.Name = "ProgBar"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 558
$ProgBar.Size = $System_Drawing_Size
$ProgBar.Style = 0
$ProgBar.Step = 1
$ProgBar.Value = 0
$ProgBar.Maximum = 96
$ProgBar.Minimum = 0

$FormtPB.Controls.Add($global:ProgBar)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $FormtPB.WindowState
#Init the OnLoad event to correct the initial state of the form
$FormtPB.add_Load($OnLoad_State_Correction)
#Show the Form
$FormtPB.show() | Out-Null
}


#endregion ProgBar-Aviable

#region ProgBar-Update

function ProgBar-Update
{
PARAM
(
[Parameter(Mandatory=$false,HelpMessage="Main Window Text")][String] $NewFormText = $global:FormtPB.Text ,
[Parameter(Mandatory=$false,HelpMessage="What you are doning at the moment")][String] $NewDoingText = $global:FormtPB_LBL.Text,
[Parameter(Mandatory=$false,HelpMessage="Pecent filled of the progess bar")][double] $ProgBarStatus = $global:ProgBar.Value,
[Parameter(Mandatory=$false,HelpMessage="Appear_Time in Seconds:")][bool] $ShowProgBarWindow = $true
)

PROCESS
{

$global:ProgBar.Value = $ProgBarStatus

if( $NewFormText -ne $global:FormtPB.Text)
{
$global:FormtPB.Text = $NewFormText
}

if( $NewDoingText -ne $global:FormtPB_LBL.Text)
{
$global:FormtPB_LBL.Text = $NewDoingText
}

If($ShowProgBarWindow -eq $false)
{
$global:FormtPB.close()
}
}
}

#endregion ProgBar-Update



#region MAIN

ProgBar-Aviable

ProgBar-Update -NewFormText "TESTING"

ProgBar-Update -ProgBarStatus 1.00 -NewDoingText "1%"
Read-Host
ProgBar-Update -ProgBarStatus 10.00 -NewDoingText "10%"
Read-Host
ProgBar-Update -ProgBarStatus 80.00 -NewDoingText "80%"
Read-Host
ProgBar-Update -ProgBarStatus 96.00 -NewDoingText "96%"
Read-Host
ProgBar-Update -ShowProgBarWindow $false

#endregion MAIN
by DonJ at 2013-02-08 07:45:08
You’ve set the max value to 96, yes? I see where you set it to 96, which should completely fill the progress bar - that’s what you expect to happen?
by mk.maddin at 2013-02-08 10:20:17
Yes I know.

I set it to 96 because in previous try, I was able to come up to 100% with setting maximum to 96 and value to 100.

But this doesn’t work now.

The main thing I want to be able to do, is to set value to any percent I want and the progess bar shows exactly this percent.
Best would be not only percent like 10 or 86, but like 10.12% or 86.23%.

Any Idea?
by DonJ at 2013-02-08 10:27:32
The control only does integers. If you needed fractions you’d set to max to 1000 and feed it something like 823 instead of 82.30. In terms of it not reaching 100 for you, I’ve not had that problem. If the value=max it always goes full. Try adding some debug code (it’s a little tough to do this while just looking at your code here) to output the value you’re setting and ensure its really hitting max at the end.