Detecting X button click of a window in winforms.
How can I detect the click event of the close (X) button at the top right corner of the control box of a form/window? Please note, I don't want to know about CloseReason, FormClosing, FormClosed or stuffs like these, unless they are inevitable. I exactly want to detect if the user clicked the X button of the form. Thanks.
Re: Detecting X button click of a window in winforms.
I think you need to do 2 things. 1 check the closereason and 2 set a flag anywhere you close the form through code. The closereason will = 3 if the x was clicked or you exited through code so if you set a flag just before you call your close method then in the closing event you check both your flag and the close reason you should be able to tell.
Flag is false and closereason is 3 x was clicked.