Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Extending DialogResult or?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WP - 15 Mar 2008 18:00 GMT
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
Bob Powell [MVP] - 15 Mar 2008 18:34 GMT
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.

Signature

--
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.

> 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
[quoted text clipped - 25 lines]
>
> - Eric
RobinS - 16 Mar 2008 04:35 GMT
> 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
[quoted text clipped - 25 lines]
>
> - 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.