Auto refresh a form (textbox output) using 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 5 years and 2 weeks 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
PS_Studio_User
Posts: 8
Last visit: Mon Apr 08, 2019 12:33 pm

Auto refresh a form (textbox output) using timer?

Post by PS_Studio_User »

Hey there, I'm trying to refresh the output to a few textbox's in a form. I'm pulling file count at certain folder locations and this changes constantly. I want to auto 'refresh' the form every 5 minutes or so to get the latest count.

Is this possible to do with a timer? I see the documentation here (https://www.sapien.com/blog/2011/08/09/ ... r-control/) for timer, but nothing to actually refresh data output to a form

Thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Auto refresh a form (textbox output) using timer?

Post by jvierra »

To refresh data you have to reacquire the newer data and update the form. The text in a textbox cannot be changed by any refresh method.
User avatar
PS_Studio_User
Posts: 8
Last visit: Mon Apr 08, 2019 12:33 pm

Re: Auto refresh a form (textbox output) using timer?

Post by PS_Studio_User »

jvierra wrote: Wed Mar 27, 2019 4:54 pm To refresh data you have to reacquire the newer data and update the form. The text in a textbox cannot be changed by any refresh method.
Thanks Jvierra, is there an easy way to update the form?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Auto refresh a form (textbox output) using timer?

Post by jvierra »

What do you mean by "update"?
User avatar
PS_Studio_User
Posts: 8
Last visit: Mon Apr 08, 2019 12:33 pm

Re: Auto refresh a form (textbox output) using timer?

Post by PS_Studio_User »

jvierra wrote: Wed Mar 27, 2019 6:44 pm What do you mean by "update"?
You said I'll need to reacquire the data and update the form, I guess I'm asking if there's a way to automatically do that or does it need to be manual?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Auto refresh a form (textbox output) using timer?

Post by jvierra »

Without an example of what you are asking bout it is not possible to understand your issue.
User avatar
PS_Studio_User
Posts: 8
Last visit: Mon Apr 08, 2019 12:33 pm

Re: Auto refresh a form (textbox output) using timer?

Post by PS_Studio_User »

jvierra wrote: Thu Mar 28, 2019 1:01 am Without an example of what you are asking bout it is not possible to understand your issue.
Sorry Jvierra, here's an example:

$Total = get count of files at folder location
$TextBox.Text = $Total
Textbox outputs total file count, so say [ 301 ]

However, file count is constantly changing in this folder, maybe its' 241 now, I'd like to somehow have the textbox refresh or update to show the new count maybe every 30 seconds, or 60 seconds - something like that.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Auto refresh a form (textbox output) using timer?

Post by jvierra »

There is no automatic way to do that. You have to redo the query and reassign the value to the textbox.
By the way. This is how to do that.

$TextBox.Text = (Get-ChildItem $folder -FIle).Count

You can stick that in the timer even and set the timer to run as often as you like.
User avatar
PS_Studio_User
Posts: 8
Last visit: Mon Apr 08, 2019 12:33 pm

Re: Auto refresh a form (textbox output) using timer?

Post by PS_Studio_User »

Thanks for the update - I've looked at using a timer with this article: https://www.sapien.com/blog/2011/08/09/ ... r-control/

But it only talks about using a timer as just a timer.

Do I just start the timer, run the PS within that, and then stop the timer, then somehow loop it?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Auto refresh a form (textbox output) using timer?

Post by jvierra »

The code goes in the timer tick event. Each time the timer ticks the code is executed.
This topic is 5 years and 2 weeks 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