Capturing Close Events

  • Thread starter Thread starter orekin
  • Start date Start date
O

orekin

Hi

The application I am working on has a starting screen with some
configuration choices and the following:
- OK button
- QUIT button
- x button in the Control/System menu box (top right corner)

The user may quit the application by pressing 'QUIT' or x, or the user
may continue with the application by pressing 'OK'. In both cases,
the form is closed.

You can prboably see where I am going here ... In the form closing
event, I want to be able to capture if the user has :
- pressed OK; or
- clicked x or clicked QUIT (both x and QUIT are handled exactly the
same way)

At the moment I am storing a boolean variable
'CloseRequestSentFromOKbutton' and it works, but surely there must be
a better way?

Thanks
Orekin
 
Orekin,

It is the same as your solution however looks in my opinion more elegant.

\\\
private void button1_Click(object sender,
System.EventArgs e)
{
this.Tag = "button1";
this.Close();
}
private void FormClosing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if ((string) this.Tag == "button1")
MessageBox.Show("button1");
}
///
I hope this helps anyhow.

cor
 
Hi,

It look as a simple modal form (ShowDialog()) for me.

Why do not set:
btnOK.DialogResult=DialogResult.OK;
btnQuit.DialogResult=DialogResult.Cancel;

In main form you've got to show this form by ShowDialog()
and check it result. If it return OK then show main form
else close main form.

HTH
Marcin

PS: Catching close event is not good choice in modal form.
 
Back
Top