Reputation: 33
I search the way to blink a text label in a windows.form. This is a part of my script :
$Form = New-Object system.Windows.Forms.Form
$Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$Form.ClientSize = '600,800'
$Form.text = "USMT - Sauvegarde des profils"
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "1. Chemin vers scanstate.exe :"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(20,10)
$Label1.Font = 'Microsoft Sans Serif,10'
Here I search a solution to blink $Label1.text
Thanks for help !
Upvotes: 0
Views: 2206
Reputation: 125277
You can create a System.Windows.Forms.Timer
object and set its Interval
to a suitable value (milliseconds) and then by handling its Tick
event, do whatever you need to blink the label, for example toggle visibility of the label. You need to start the timer when loading form:
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$label = New-Object System.Windows.Forms.Label
$label.Text = "This is my label."
$label.AutoSize = $true
$form.Controls.Add($label)
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 250
$timer.Add_Tick({$label.Visible = -not($label.Visible)})
$form.Add_Load({$timer.Start()})
$form.ShowDialog()
$timer.Dispose()
$form.Dispose()
Upvotes: 1
Reputation: 354744
Create a timer, add an event handler to its Tick
event and toggle visibility of the label from there. Creating GUIs and reacting to events isn't particularly nice in PowerShell, but it can be done.
Upvotes: 1