1
Reply

Minimize on close, but only from X

jakar

jakar

Sep 11 2004 6:12 PM
2.1k
Hi, I want to prevent my main Form from closing when the X in the upper right is pressed. I am handling the Closing event, and can change the CancelEventArgs.Cancel to true. The problem is I don't want to prevent the user from closing the Form using the Exit option in the menu. The Exit menu just calls this.Close() at the moment. Should the Exit menu call something else? Or is there a way to differenciate who initiated the call? During either operation, the "sender" to the Closing event is the Form. I guess I could just set a bool value on the Form that tells me not to exit the application, then set the value to say exit the application during the menu Exit, just before calling this.Close(). Is there a cleaner way of doing this?

Answers (1)