Home All Groups Group Topic Archive Search About
Author
12 Apr 2005 5:53 AM
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

Author
12 Apr 2005 7:28 AM
Cor Ligthert
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
Are all your drivers up to date? click for free checkup

Author
12 Apr 2005 7:33 AM
Marcin Grzębski
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.

Show quoteHide quote
> 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

Bookmark and Share