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.
This topic is 2 years and 9 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
GHIsolierung
Posts: 62
Last visit: Tue Nov 02, 2021 12:46 am

Run code after gui is loaded

Post by GHIsolierung »

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 112 times
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 7:24 am
Answers: 39
Been upvoted: 30 times

Re: Run code after gui is loaded

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney
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: 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
GHIsolierung
Posts: 62
Last visit: Tue Nov 02, 2021 12:46 am

Re: Run code after gui is loaded

Post by GHIsolierung »

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: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 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
GHIsolierung
Posts: 62
Last visit: Tue Nov 02, 2021 12:46 am

Re: Run code after gui is loaded

Post by GHIsolierung »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 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.
This topic is 2 years and 9 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