Referencing Variables across the events

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 7 years and 4 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Referencing Variables across the events

Post by jvierra »

The issue has nothing to do with PSS. It is a PowerShell specification.

The thing that fools most is that forms events are really functions. We assign a script block to the event handler which is cast to a "delegate" which is like a function. It has a scope local to the script block. All variables created or changed in a form event are not visible outside of the event. All controls are visible and can be changed from an event. This is what a "delegate" is used for in a form.

Forms are not like PS1 scripts because they use events and can queue events.
This topic is 7 years and 4 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