×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Setup a counter in powershell winform

Setup a counter in powershell winform

Setup a counter in powershell winform

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close