locked
Create a Dialog box with YES NO CANCEL Options C# RRS feed

  • Question

  • Hi some one let me know how to create a dialog box with 3 options like 'Yes', 'No' and 'Cancel' buttons on that. (i am working in C# windows appliaction)

    Monday, August 1, 2011 7:57 AM

Answers

  • Another with if, else if blocks:

    DialogResult result = MessageBox.Show("Do you wanna do something?", "Warning", 
    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
    if(result == DialogResult.Yes)
    {
       //code for Yes
    }
    else if(result == DialogResult.No)
    {
      //code for No
    }
    else if (result == DialogResult.Cancel)
    {
      //code for Cancel
    }
    



    Mitja
    • Marked as answer by VinayGaddam Monday, August 1, 2011 8:32 AM
    Monday, August 1, 2011 8:16 AM

All replies

  • Hi

    Is this is the one you are looking for?

    var dialogResult = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel);   


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Monday, August 1, 2011 8:11 AM
  • one way using switch method:

          switch (MessageBox.Show("Do you want to create a new file?",
                  "WonderWord",
                  MessageBoxButtons.YesNoCancel,
                  MessageBoxIcon.Question)) {
          case DialogResult.Yes:
            // "Yes" processing
            break;
    
          case DialogResult.No:
            // "No" processing
            break;
    
          case DialogResult.Cancel:
            // "Cancel" processing
            break;
    


     


    Mitja
    Monday, August 1, 2011 8:11 AM
  • Another with if, else if blocks:

    DialogResult result = MessageBox.Show("Do you wanna do something?", "Warning", 
    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
    if(result == DialogResult.Yes)
    {
       //code for Yes
    }
    else if(result == DialogResult.No)
    {
      //code for No
    }
    else if (result == DialogResult.Cancel)
    {
      //code for Cancel
    }
    



    Mitja
    • Marked as answer by VinayGaddam Monday, August 1, 2011 8:32 AM
    Monday, August 1, 2011 8:16 AM