Run code after gui is loaded

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
rubberduck
Posts: 62
Last visit: Tue Jul 06, 2021 5:13 am

Run code after gui is loaded

Post by rubberduck »

Product: PowerShell Studio 2020 (64 Bit)
Build: v5.7.172
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18363.0
PowerShell version(s): 5.1.18362

I refer here to my own entry:
viewtopic.php?p=80198#p80198

The task is simple:
I want to execute code, or call a function, or run a job AFTER a GUI has been loaded.
So in other words, I want my GUI to be there first and THEN perform any actions.
Plain and simple.

To do this, I create a new GUI project, create a job that collects data, and display that collected data in the GUI in a text field.
But what happens now is that the job is always executed first and the GUI starts only then, which leads to a considerable startup delay.

How can I change this behavior.

thanks for your help in advance.
Thomas

The relevant code is:
Code.txt
(2.57 KiB) Downloaded 49 times

User avatar
brittneyr
Site Admin
Posts: 818
Last visit: Fri Jul 30, 2021 12:06 pm
Answers: 16
Been upvoted: 13 times

Re: Run code after gui is loaded

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney Ryn
SAPIEN Technologies, Inc.

jvierra
Posts: 14885
Last visit: Sun Aug 01, 2021 3:12 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Run code after gui is loaded

Post by jvierra »

See the following articles:

https://info.sapien.com/index.php/guis/ ... sive-loops
https://info.sapien.com/index.php/guis/ ... sive-forms

There are many articlkes on that page that you will need to review to learn how to work with WinForms and PowerShell.

User avatar
rubberduck
Posts: 62
Last visit: Tue Jul 06, 2021 5:13 am

Re: Run code after gui is loaded

Post by rubberduck »

Thanks for your reply, those are both sites I know.
However, that is not my real problem.
I want to display a GUI - wait 2 seconds after that if I want - and then I want to perform some action.
With the pages you showed me, I would have a gui that I can 'move' in the meantime of the job, but it doesn't fix my problem with the order.

User avatar
Alexander Riedel
Posts: 7719
Last visit: Sat Jul 31, 2021 12:28 pm
Answers: 4
Been upvoted: 10 times

Re: Run code after gui is loaded

Post by Alexander Riedel »

https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

That would be the Form.Shown event. The Microsoft website https://docs.microsoft.com/en-us/dotnet ... esktop-4.8
has a brief explanation and order of Windows Forms events.

A google search for <windows forms events> produces additional examples and documentation.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
rubberduck
Posts: 62
Last visit: Tue Jul 06, 2021 5:13 am

Re: Run code after gui is loaded

Post by rubberduck »

To be honest, I don't feel like watching all the documentaries.
I am not a programmer anyway and never want to become one.
That's why I go to professionals and pay licenses for support. ;)

Would it be possible, you could give me a possible solution based on the code I provided?
Thank you very much.

jvierra
Posts: 14885
Last visit: Sun Aug 01, 2021 3:12 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: Run code after gui is loaded

Post by jvierra »

Sorry but this is not product support. There are other forums for product support. ALso note that basic programming and reading instructions are not part of any support for any product.

The links are not videos they are explanations and instructions on how to proceed to do what you ask. Why should I write the whiole thing all over when someone did such a good job or that already?

The instructions are short and can be read in less than ten minutes.

A simple hiont is to use a timer or use thee forn "Shown" event. That won't necessarily do what you ask so the whole of possibilites are described in the two articles.

User avatar
Alexander Riedel
Posts: 7719
Last visit: Sat Jul 31, 2021 12:28 pm
Answers: 4
Been upvoted: 10 times

Re: Run code after gui is loaded

Post by Alexander Riedel »

The product purchase includes product support. It does not mean we will be writing the code for you.
Kind of like asking Microsoft do write your essay because you have an Office license :D

Go read the articles, they don't bite and it feels good to accomplish something.
Alexander Riedel
SAPIEN Technologies, Inc.

Locked