PictureBox Timer

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 4 years and 11 months 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
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

PictureBox Timer

Post by dlaurora »

Hello everyone.

Is there any way to show during form load a splash window?

My From takes 16 seconds to load, due to some modules, and I want to add a Gif inside a PictureBox to be shown during that time? is this possible? I know that Studio has a timer but don't know how to use it, I've seen some examples and try to replicate them using the PictureBox but it did not work.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PictureBox Timer

Post by jvierra »

Just add a timer from the toolbox. You can use the timer default event to do things at each timer tick.

For instructions and example on how to use the Timer control see: https://info.sapien.com/index.php/guis/ ... er-control
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Re: PictureBox Timer

Post by dlaurora »

I've tried to do that but not sure how to get it to work. tried to modify some elements from the example, well thanks for the info, I'll keep practicing
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: PictureBox Timer

Post by davidc »

I been meaning to create a function snippet to show a splash screen. Let me see if I can get something in for the next service release of PowerShell Studio.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PictureBox Timer

Post by jvierra »

David to the rescue. Good idea.

Here is a sample of how to use a timer.

Code: Select all

Add-Type -AssemblyName System.Windows.Forms

# control creation
$form = New-Object System.Windows.Forms.Form
$buttonOK = New-Object System.Windows.Forms.Button
$form.Controls.Add($buttonOK)
$timer = New-Object System.Windows.Forms.Timer

# form settings
$form.StartPosition = 'CenterScreen'
$form.Text = 'Basic Form Demo'
$form.add_Load({$timer.Start()})

# buttonOK settings
$buttonOK.Text = 'Ok'
$buttonOK.DialogResult = 'Ok'

#timer settings
$timer.Interval = 1000 # on second
$timer.add_Tick({Write-Host 'Tick!'})

$form.ShowDialog()
This is from my "snippet" store and I just added the timer to show how it works in a form and how to access and set the event. PowerShell Studio does all of this for you in a few clicks.
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Re: PictureBox Timer

Post by dlaurora »

Yup that will be a great Idea, per your example, this will only work with text?

$TotalTime = 5 #in seconds
$script:StartTime = (Get-Date).AddSeconds($TotalTime)
$timer1.Start()
$timer1_Tick = {

[TimeSpan]$span = $script:StartTime - (Get-Date)
$picturebox.Visible = $true
$textbox2.Visible = $true # here should show both textbox and pictubox

if ($span.TotalSeconds -le 0)
{
$timerUpdate.Stop()
$picturebox.Visible = $false
$textbox2.Visible = $false
}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PictureBox Timer

Post by jvierra »

What are you trying to say?
TotalSeconds will never change in your example. Something has to decrement the span.

If you are looking for an elapsed time timer then just set the timer to 16000 and stop it when the event is expired.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PictureBox Timer

Post by jvierra »

You can also just add an elapsed time timer at any time in the form. On load or a button click.

Code: Select all

$form1_Load={
    $timer = [System.Timers.Timer]::New(16000)
    $timer.AutoReset = $false
    $timer.SynchronizingObject = $form1
    $timer.add_Elapsed({
            Write-Host 'Done!'
    })
    $timer.Start()
}
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Re: PictureBox Timer

Post by dlaurora »

That just did the trick and so simple, I was writing a lot of thing with no sense, thanks!!!!!!! :D :D :D :D :D :D
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: PictureBox Timer

Post by davidc »

The splash screen snippet is now available:

https://www.sapien.com/blog/2019/04/16/ ... ns-batman/
David
SAPIEN Technologies, Inc.
This topic is 4 years and 11 months 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