-2

Cannot convert from 'System.Windows.Forms.MessageBoxButtons' to 'string'

Which I had no idea for

MessageBox.Show("Problem generating the quiz.Sorry!", MessageBoxButtons.OK, MessageBoxIcon.Error

Random rdmNumber = new Random();
number1 = rdmNumber.Next(0, 10);
number2 = rdmNumber.Next(0, 10);
int selectOp = rdmNumber.Next(0, 4);
operation = "";
switch (selectOp)
{
    case 1:
        operation = " + ";
        solution = number1 + number2;
        break;
    case 2:
        operation = " - ";
        if (number1 < number2)
        {
            int temp = number1;
            number1 = number2;
            number2 = temp;
        }
        solution = number1 - number2;
        break;
    case 3:
        operation = " x ";
        solution = number1 * number2;
        break;
    case 4:
        operation = " % "; // take out the extra equal sign
        solution = number1 % number2;
        break;
    default:
        MessageBox.Show("Problem generating the quiz.Sorry!", 
        MessageBoxButtons.OK, MessageBoxIcon.Error);
        break;
}
1
  • You need to enter the mbox title before the button and after the message...
    – Niklas
    Commented Apr 10, 2017 at 22:29

1 Answer 1

6

You're missing the caption element of the MessageBox

MessageBox.Show("Problem generating the quiz.Sorry!", "Caption",
            MessageBoxButtons.OK, MessageBoxIcon.Error);

The documentation:

MessageBox.Show Method (String, String, MessageBoxButtons, MessageBoxIcon)

4
  • See docs msdn.microsoft.com/de-de/library/0x49kd7z(v=vs.110).aspx
    – Jérôme
    Commented Apr 10, 2017 at 22:30
  • @Jérôme Thanks was about to add it.
    – I.B
    Commented Apr 10, 2017 at 22:32
  • Thank you so much I was stuck at that part. But, It's hard for beginners like me.
    – Vincent
    Commented Apr 10, 2017 at 23:26
  • @Vincent It's okay we all have to start somewhere. I'm happy I could help :)
    – I.B
    Commented Apr 10, 2017 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.