Capturing the Close/Exit Events

Mar 10, 2010 at 4:14 PM

Can we use this to capture the form close or exit events?

We have been trying to find a way to capture this event on a PowerShell form to do some cleanup when the user clicks the X, but we can't seem to figure it out.

It has been a while since I wrote any .NET code so, my knowledge on event handlers is a little rusty.

Thank You,

Kevin

Coordinator
Mar 10, 2010 at 4:37 PM

Hi Kevin,

Yes, you could use this for that. Before we proceed though, are you using powershell 1.0 or 2.0? Because 2.0 has built in support for event handling.

-Oisin

Mar 15, 2010 at 5:14 PM

Yes we are using Powershell 2.0.  We have not been able to find any good documentation on event handling with Powershell 1 or 2.

If you have any information or docs to send us to, or even an example :)  that would be appreciated.

Thank You,

Kevin

Coordinator
Apr 1, 2010 at 4:37 PM

Here's an example in v1 style: http://www.techotopia.com/index.php/Creating_GUIs_in_Windows_PowerShell_1.0_with_WinForms

here's some with v2: http://powershell.labs.oreilly.com/ch31.html and http://powershell.labs.oreilly.com/ch13.html#program_add_a_graphical_user_interface_t

-Oisin