Catch the closing event of a form when clicked on X

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
 
P

Peter Foot [MVP]

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
 
M

Michael Maier

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top