Starting a timer on load

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mitchell_loftis
Posts: 4
Last visit: Mon Sep 18, 2023 2:44 pm

Starting a timer on load

Post by mitchell_loftis »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2018 5.5.150
32 or 64 bit version of product: 64
Operating system: Windows 10
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

I'm trying to tell my form "2017Warp" to automatically start a timer named timerUpdate when the form is loaded. I have set the timer to 5 seconds for testing. When the timer expires, I want to perform a click on the form's start button ($buttonStart). My code is below. My issue is I can't get the timer to start.

$form2017WarpDr_Load= {

$ProgressLabel.Text = "This will terminate any active sessions. Press Start to continue"
$progress.Visible = $false

$LabelTime.Text = "Will start automatically in: {0:D1}" -f $TimeoutSeconds
$script:StartTime = (Get-Date).AddSeconds($TimeoutSeconds)
$timerUpdate.Start()
}

$TimeoutSeconds = 5

$timeout_Tick = {
#TODO: Place custom script here
[TimeSpan]$span = $script:StartTime - (Get-Date)

$LabelTime.Text = "Will start automatically in: {0:N0}" -f $span.TotalSeconds

If ($span.TotalSeconds -le 0)
{
$buttonStart.PerformClick()
}
}

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
cody m

Re: Starting a timer on load

Post by cody m »

[TOPIC MOVED BY MODERATOR]

If the code above is all of what you have make sure that you have a click event for the buttonStart button.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Starting a timer on load

Post by jvierra »

Start by adding this line first:

$timerUpdate.Enabled = $true
This topic is 6 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked