Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setup a counter in powershell winform

Status
Not open for further replies.

Christine Silva

Technical User
Aug 1, 2021
1
BR
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top