Extending DialogResult or?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WP

    Extending DialogResult or?

    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.Wh atever)
    // User pressed the Save button

    - Eric
  • Bob Powell [MVP]

    #2
    Re: Extending DialogResult or?

    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


    Find great Windows Forms articles in Windows Forms Tips and Tricks


    Answer those GDI+ questions with the GDI+ FAQ


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


    "WP" <mindcooler@gma il.comwrote in message
    news:3dbb85ec-c0b3-4534-99b2-1b2bdc7bed19@d4 g2000prg.google groups.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.Wh atever)
    // User pressed the Save button
    >
    - Eric

    Comment

    • RobinS

      #3
      Re: Extending DialogResult or?

      "WP" <mindcooler@gma il.comwrote in message
      news:3dbb85ec-c0b3-4534-99b2-1b2bdc7bed19@d4 g2000prg.google groups.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.Wh atever)
      // 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

      Comment

      Working...