Wednesday, July 16, 2008 12:26 AMHi Everyone,
Could you please help with a little problem. I have code a very simple Windows Form that closes the form. I want to capture an event where the user has instigated the close by clicking the Close Button (red x), rather than a close instigated by code.
The Closing event fires when both ways of closing the form is used, but I want to differentiate between the two ways and capture the click event of the Close Button.
Any ideas where I could find information on this?
Wednesday, July 16, 2008 12:57 AMHi,
In the FormClosing event th FormClosingEventArg has a property tha's called CloseReason. This is very usefull becouse if you want the Form to stop closing if the closing reason was CloseReason.UserClosing you can do (FromClosingEventArg.Cancel = true ) then do something in your code and finally close the form programatically(or use another logic ). The FormClosedEventArg has the same CloseReason property but then you can't stop the Form from closing.
Hope this help.
Wednesday, July 16, 2008 1:06 AMExactly what I am looking for, thanks Camilo :)
Friday, January 27, 2012 11:45 PM
The problem with this is that both programmatic close and the Red X has the same CloeseReason. : Userclosing
So if I want to delay the close triggered by the user, do some cleanup and then do a form1.Close() I'll be stuck in an endless loop