This project is read-only.

Capturing the Close/Exit Events

Mar 10, 2010 at 5: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,


Mar 10, 2010 at 5: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.


Mar 15, 2010 at 6: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,


Apr 1, 2010 at 5:37 PM

Here's an example in v1 style:

here's some with v2: and