Here is how to do it: override
System::Windows::Forms::Form.OnFormClosing
method:
virtual void OnFormClosing(System::Object ^sender, System::Windows::Forms::FormClosingEventArgs ^e) {
if (e->CloseReason == System::Windows::Forms::CloseReason::UserClosing) {
Hide();
e->Cancel = true;
} }
You don't need to worry about
Dispose
, it will be called as the form is kept under the
Application
.
[EDIT]
Overriding this method is certainly better than handling the event
FormClosing
. In the codelet shown above, Hide is actually "
this->Hide()
", so the instance is already passed to the method. With event, sender needs to be typecast to
Form
.
—SA