Catch the closing event of a form when clicked on X

  • Thread starter Thread starter Michael Maier
  • Start date Start date
M

Michael Maier

Hi,

I'd like to catch the click on the x of the form (that closes the form).
In a normal application I would use the Closing event and then ask for
e.CloseReason... this would tell me if I have clicked to close the form,
or if the form was closed programatically... the problem is, in the
first case I'd like the application to exit in the second I'd like to
open another form...
Can anyone help?

Thanks,
Michael
 
The way around this is to write your own method to close the form
programmatically e.g.
private bool closedProgrammatically;
public void CloseWithFlag()
{
closedProgrammatically = true;
this.Close();
}

Then in your Closing event you can check the value of this boolean flag as
you would with the built in functionality in the desktop framework.

Peter
 
oh yeah.... you're right... could have thought of that by myself... :-(
I guess I have to develop this way of thinking, when it comes to CF...

Thanks a lot,
Michael
 
Back
Top