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.
Locked
User avatar
rkirchhof
Posts: 5
Joined: Sun Mar 03, 2013 12:42 pm

how do I programmatically close a form?

Post by rkirchhof » Fri Apr 05, 2013 11:57 am

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
Joined: Thu Aug 18, 2011 4:56 am

Re: how do I programmatically close a form?

Post by davidc » Fri Apr 05, 2013 12:09 pm

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.

Locked