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.
Locked
User avatar
dlaurora
Posts: 23
Joined: Wed Oct 26, 2016 10:43 am

PictureBox Timer

Post by dlaurora » Fri Mar 15, 2019 12:57 pm

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.

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PictureBox Timer

Post by jvierra » Fri Mar 15, 2019 1:39 pm

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: 23
Joined: Wed Oct 26, 2016 10:43 am

Re: PictureBox Timer

Post by dlaurora » Fri Mar 15, 2019 2:06 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: PictureBox Timer

Post by davidc » Fri Mar 15, 2019 2:08 pm

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.

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PictureBox Timer

Post by jvierra » Fri Mar 15, 2019 2:22 pm

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: 23
Joined: Wed Oct 26, 2016 10:43 am

Re: PictureBox Timer

Post by dlaurora » Fri Mar 15, 2019 2:29 pm

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
}
}

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PictureBox Timer

Post by jvierra » Fri Mar 15, 2019 2:56 pm

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.

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PictureBox Timer

Post by jvierra » Fri Mar 15, 2019 3:01 pm

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: 23
Joined: Wed Oct 26, 2016 10:43 am

Re: PictureBox Timer

Post by dlaurora » Fri Mar 15, 2019 3:19 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: PictureBox Timer

Post by davidc » Tue Apr 16, 2019 7:10 am

The splash screen snippet is now available:

https://www.sapien.com/blog/2019/04/16/ ... ns-batman/
David
SAPIEN Technologies, Inc.

Locked