Thanks, Curtis, but I'm getting this error message: "Cannot assign to 'Close' because it is a 'method group'.
I've also tried the OnClosed and OnClosing events of the main window. There are no errors, but, strangely, they are not fired when I close the window, but only when I quit the application.