Christine Silva
Technical User
Hello
I wrote this form as an example, it will show a winform with a label on it and it has a counter to auto close the form after 5 seconds.
_______________________________________________________________________________________________
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(345,150)
$form.StartPosition = 'CenterScreen'
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(40,42)
$label.Size = New-Object System.Drawing.Size(300,20)
$label.Text = 'SOMETHING WRITTEN HERE AS A LABEL ... !'
$form.Controls.Add($label)
$Script:Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 1000
Function Timer_Tick()
{
--$Script:CountDown
If ($Script:CountDown -lt 0)
{
$Timer.Stop();
$Form.Close();
$Timer.Dispose();
$Script:CountDown = 5
}
}
$Script:CountDown = 5
$Timer.Add_Tick({ Timer_Tick})
$Timer.Start()
$Form.ShowDialog() | Out-Null
______________________________________________________________________________________________
This is a script that shows a simple 5 seconds numerical counter.
for ($i = 1; $i -le 5; $i++ )
{
Write-Progress -Activity " " -Status "$i"
Start-Sleep -Milliseconds 1000
}
_______________________________________________________________________________________________
I need to put this all together, so this numerical counter shows up in the middle of the winform, bellow the label ...
Any help would be much appreciated.
I wrote this form as an example, it will show a winform with a label on it and it has a counter to auto close the form after 5 seconds.
_______________________________________________________________________________________________
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(345,150)
$form.StartPosition = 'CenterScreen'
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(40,42)
$label.Size = New-Object System.Drawing.Size(300,20)
$label.Text = 'SOMETHING WRITTEN HERE AS A LABEL ... !'
$form.Controls.Add($label)
$Script:Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 1000
Function Timer_Tick()
{
--$Script:CountDown
If ($Script:CountDown -lt 0)
{
$Timer.Stop();
$Form.Close();
$Timer.Dispose();
$Script:CountDown = 5
}
}
$Script:CountDown = 5
$Timer.Add_Tick({ Timer_Tick})
$Timer.Start()
$Form.ShowDialog() | Out-Null
______________________________________________________________________________________________
This is a script that shows a simple 5 seconds numerical counter.
for ($i = 1; $i -le 5; $i++ )
{
Write-Progress -Activity " " -Status "$i"
Start-Sleep -Milliseconds 1000
}
_______________________________________________________________________________________________
I need to put this all together, so this numerical counter shows up in the middle of the winform, bellow the label ...
Any help would be much appreciated.