Hello, I making and Windows Forms program and I have a dialog with two
buttons. I have set the DialogResult property for these buttons to
DialogResult.OK and DialogResult.No, respectively (however, these
buttons are not labelled "OK" and "No"). Settting this property is
very convenient, I don't need to write any code determining what
should happen when one of these buttons is clicked. Anyway, now I need
to add a third button and I guess I could set its DialogResult
property to some value (just not DialogResult.OK or DialogResult.No)
but one thing that bothers me is that these property values (OK, No,
whatever) doesn't really tranlaste well to what the buttons actually
mean for this particular dialog. I want to know if I can "extend"
DialogResult with some new constants? Another approach would be, I
guess is to introduce a new property MyDialogResult and have the user
check that after displaying the dialog instead of checking the
returned DialogResult. Then I could continue to use DialogResult for
my buttons and get click handling "for free".
What do you suggest here?

What I'm trying to get away from is this:
DialogResult res = dlg.ShowDialog(this);

if (res == DialogResult.OK)
// User pressed the play button
else if (res == DialogResult.No)
// User pressed the stop button
else if (res == DialogResult.Whatever)
// User pressed the Save button

- Eric

Re: Extending DialogResult or? by Bob

Bob
Sat Mar 15 12:34:34 CDT 2008

You can only return a DialogResult value. The preferred method your case
would be to return OK for all buttons except for the cancel and provide a
property in which you will store the result you really want to communicate.

Extending DialogResult is impossible because you cannot inherit from an
enum.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"WP" <mindcooler@gmail.com> wrote in message
news:3dbb85ec-c0b3-4534-99b2-1b2bdc7bed19@d4g2000prg.googlegroups.com...
> Hello, I making and Windows Forms program and I have a dialog with two
> buttons. I have set the DialogResult property for these buttons to
> DialogResult.OK and DialogResult.No, respectively (however, these
> buttons are not labelled "OK" and "No"). Settting this property is
> very convenient, I don't need to write any code determining what
> should happen when one of these buttons is clicked. Anyway, now I need
> to add a third button and I guess I could set its DialogResult
> property to some value (just not DialogResult.OK or DialogResult.No)
> but one thing that bothers me is that these property values (OK, No,
> whatever) doesn't really tranlaste well to what the buttons actually
> mean for this particular dialog. I want to know if I can "extend"
> DialogResult with some new constants? Another approach would be, I
> guess is to introduce a new property MyDialogResult and have the user
> check that after displaying the dialog instead of checking the
> returned DialogResult. Then I could continue to use DialogResult for
> my buttons and get click handling "for free".
> What do you suggest here?
>
> What I'm trying to get away from is this:
> DialogResult res = dlg.ShowDialog(this);
>
> if (res == DialogResult.OK)
> // User pressed the play button
> else if (res == DialogResult.No)
> // User pressed the stop button
> else if (res == DialogResult.Whatever)
> // User pressed the Save button
>
> - Eric


Re: Extending DialogResult or? by RobinS

RobinS
Sat Mar 15 22:35:03 CDT 2008

"WP" <mindcooler@gmail.com> wrote in message
news:3dbb85ec-c0b3-4534-99b2-1b2bdc7bed19@d4g2000prg.googlegroups.com...
> Hello, I making and Windows Forms program and I have a dialog with two
> buttons. I have set the DialogResult property for these buttons to
> DialogResult.OK and DialogResult.No, respectively (however, these
> buttons are not labelled "OK" and "No"). Settting this property is
> very convenient, I don't need to write any code determining what
> should happen when one of these buttons is clicked. Anyway, now I need
> to add a third button and I guess I could set its DialogResult
> property to some value (just not DialogResult.OK or DialogResult.No)
> but one thing that bothers me is that these property values (OK, No,
> whatever) doesn't really tranlaste well to what the buttons actually
> mean for this particular dialog. I want to know if I can "extend"
> DialogResult with some new constants? Another approach would be, I
> guess is to introduce a new property MyDialogResult and have the user
> check that after displaying the dialog instead of checking the
> returned DialogResult. Then I could continue to use DialogResult for
> my buttons and get click handling "for free".
> What do you suggest here?
>
> What I'm trying to get away from is this:
> DialogResult res = dlg.ShowDialog(this);
>
> if (res == DialogResult.OK)
> // User pressed the play button
> else if (res == DialogResult.No)
> // User pressed the stop button
> else if (res == DialogResult.Whatever)
> // User pressed the Save button
>
> - Eric

I've handled this by setting a property in the dialog and reading it from
the calling form before disposing of the dialog, which you mention in your
post. It gives you possibilities.

RobinS.
GoldMail.com