how do I programmatically close a form?

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 11 years and 1 week 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
rkirchhof
Posts: 5
Last visit: Mon Apr 08, 2013 5:50 am

how do I programmatically close a form?

Post by rkirchhof »

I've just learned how to open one with call-MyForm_pff, but how do I close it when I'm finished with it? me.close() aint it.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: how do I programmatically close a form?

Post by davidc »

Inside the form script you need to use the form variable in order to close it:
PowerShell Code
Double-click the code block to select all.
$form1.Close()
PowerShell doesn't support classes and thus "me" or "this" doesn't work. They normally reference the instance of the class.

The only time you can use $this to determine the caller of an event block.

David
David
SAPIEN Technologies, Inc.
This topic is 11 years and 1 week 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