Load GUI before starting the processes

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 8 years and 8 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
gutihz
Posts: 38
Last visit: Fri Nov 10, 2023 10:54 am

Load GUI before starting the processes

Post by gutihz »

Hi Everyone,

I'm having a problem where I can't figure out how to load the GUI first then start all the processes that the application should be doing (without a start button).

I have few things that the application does such as copies, checks registry and so forth.
If I put everything under "OnLoadFormEvent", The all processes start before the GUI even starts. If I do start-sleep, the whole process stops then without the GUI loading the processes start.

If I put the processes under a startbutton, the gui loads fine and clicking the start button starts the processes.

I also couldn't figure out how to automatically adjust the GUI on the size of the monitor. If anyone has an input on that as well, really appreciated.


Can anyone tell me how I can accomplish this?

Thanks in advance.

1. Product, version and build - PowerShell Studio 2015, 4.2.89
2. 32 or 64 bit product - 64-bit
3. Operating system, e.g.- Windows 7 64-bit
4. Attach a screenshot, if applicable - N/A
5. Attach logs, crash reports, etc., in a ZIP file - N/A
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Load GUI before starting the processes

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, gutihz.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PowerShell Studio 2014, Version & Build: 4.1.71. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
User avatar
gutihz
Posts: 38
Last visit: Fri Nov 10, 2023 10:54 am

Re: Load GUI before starting the processes

Post by gutihz »

Anyone? :roll: :roll: :roll:
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Load GUI before starting the processes

Post by davidc »

[MOVED TO POWERSHELL GUI FORUM BY MODERATOR]

You can look at using jobs, see:

https://www.sapien.com/blog/2012/05/16/powershell-studio-creating-responsive-forms/

Or you can use a timer control to delay load:

https://www.sapien.com/blog/2011/08/09/primalforms-2011-spotlight-on-the-timer-control/

David
David
SAPIEN Technologies, Inc.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Load GUI before starting the processes

Post by dan.potter »

Hide the startbutton and call it would be the easiest.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load GUI before starting the processes

Post by jvierra »

Dan - think about it. How would you call the start button except via timer? If you call it in the load event it changes nothing.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Load GUI before starting the processes

Post by dan.potter »

change the activated event of the form to the start button.
PowerShell Code
Double-click the code block to select all.
$form1_Load={
	#TODO: Initialize Form Controls here
	
}

$start_Click={
	#TODO: Place custom script here
	sleep 2
	$textbox1.Text = "button click"
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load GUI before starting the processes

Post by jvierra »

Yes - that will work as the activated occurs after the form is displayed. The form will still remain locked until the code completes. Using a job or the time prevents the form from locking up. So...while this allows the form to be displayed it is not what the activated event was designed to be used for. Don't get me wrong. I am not saying it can't be sued. I am just noting that it does not really solve the problem. David's references are both solutions and there are a couple ore that can be implements.
User avatar
gutihz
Posts: 38
Last visit: Fri Nov 10, 2023 10:54 am

Re: Load GUI before starting the processes

Post by gutihz »

Thank you both for your answers...

@Dan,
Sorry I'm kind of confused by what you mean to change activated event of the form? (Kind of new to this). I tried
button1_click.performclick()

but that didn't do the job.


@jvierra,

I agree with everything you said, however, I have limited time to finish this project I am working on. Automatically clicking the button would save me a lot of time. I will definitely update the code with what you recommended when I have more time.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Load GUI before starting the processes

Post by jvierra »

Fundamentally what Dan is saying is to put you code in the form activated event.

Do you know how to add an event to the form? When you see the event elect the startbutton event code for the event.
This topic is 8 years and 8 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