form.windowstate property pane and formload priority

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 1 year and 10 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
reverend97
Posts: 2
Last visit: Mon May 16, 2022 10:26 am

form.windowstate property pane and formload priority

Post by reverend97 »

I am having an issue with the form.windowstate settings not behaving as expected.

In the form_load section I have the form.windowstate property set to Normal and the form property pane windowstate value set to Minimize. When I run the project the form displays briefly then minimizes. This seems to be the opposite of what is supposed to happen. I used a form project with a blank for and just the windowstate settings to test.

Per the doc below the form property setting should take effect after the property pane value. Is this a bug or is there a setting that can flip this?

https://info.sapien.com/index.php/guis/ ... 0389339aad
>>Form Load event: Occurs before a form is displayed.
Use the Load event to initialize property values just before the form is displayed.

The values in the Properties pane of PowerShell Studio and PrimalScript are set when the objects are created (New-Object), which is shortly before the Load event is raised. You can use the Load event to get the initial values or set new values.
<<

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.206
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.19042.0
PowerShell 5
User avatar
brittneyr
Site Admin
Posts: 1654
Last visit: Wed Mar 27, 2024 1:54 pm
Answers: 39
Been upvoted: 30 times

Re: form.windowstate property pane and formload priority

Post by brittneyr »

[Topic moved to PowerShell GUIs Forum by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1654
Last visit: Wed Mar 27, 2024 1:54 pm
Answers: 39
Been upvoted: 30 times

Re: form.windowstate property pane and formload priority

Post by brittneyr »

Without seeing code it is hard to determine what is happening here.


You may find the following helpful:
https://www.sapien.com/blog/2022/01/04/ ... ll-studio/
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: form.windowstate property pane and formload priority

Post by jvierra »

Events are dispatched as Windows messages. Messages are placed into a queue and the message loop, the code that manages the queue, selects messages in a specific order. Each set of messages that affect a particular aspect of a form or control are, theoretically, retrieved in the order of the message event hierarchy.

My best guess is that, when the property of the form that sets the Windows state is executed it is executed and not a fixed property. Some design-time properties are not physical properties like size but are just hints to the system that an operation needs to be performed. Minimizing a form can only be done by the operating system and cannot be done by building a form as minimized. A form must be created as specified by size and location and cannot be minimized until it is "Shown". The "Load" event is executed before the form is "Shown" and the "Minimize" message cannot be sent until the form has processed the "Load" event. This would cause the order of the messages to occur backwards from what you may expect.

Simply, you cannot minimize a form until it is "Shown" and the "Load" property change would add the "Normal" state message into the message queue before the "Minimize" message.

This is the intent of the "Shown" event. Place the "Normal" state property assignment into the "Shown" event and it should then do what you are trying to do.

This type of event scrambling occurs and is dependent on other form properties such as hiding a form and then trying to show it again.

Learning the event dispatch order and how the message loop processes messages is the best way to gain an understanding of how these things work and how to decode odd behaviors with events. This is well documented on the Microsoft web site.
reverend97
Posts: 2
Last visit: Mon May 16, 2022 10:26 am

Re: form.windowstate property pane and formload priority

Post by reverend97 »

The Shown event fixed the issue.
Thanks very much!
This topic is 1 year and 10 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