Hide/Show problems on a questionerre application

Posted by T. Todd on Stack Overflow See other posts from Stack Overflow or by T. Todd
Published on 2012-07-03T21:12:41Z Indexed on 2012/07/03 21:15 UTC
Read the original article Hit count: 220

Filed under:
|

I am doing an assignment involving the creation of a simple Quiz type form application. However, whenever I run the program, only the first answer shows for a multiple question and I cannot for the life of me figure out why.

This is the contstructor:

            MultipleChoice dlg =
            new MultipleChoice(
            new Question("What is the capital of Zimbabwe?",
            new Answer("Paris", false),
            new Answer("Washington D.C.", false),
            new Answer("Harare", true),
            new Answer("Cairo", false),
            new Answer("N'Djamena", false)));
            if (dlg.ShowDialog() == DialogResult.OK)
            {
               if (dlg.Correct) MessageBox.Show("You got something right!");
               else MessageBox.Show("You couldn't be more wrong");
            }

And this is the Question Form Code:

private Question Q; public MultipleChoice (Question q) { Q = q; InitializeComponent(); textPrompt.Text = Q.Prompt; if (Q.A != null) { radioA.Text = Q.A.Prompt; } else radioA.Hide(); if (Q.B != null) { radioB.Text = Q.B.Prompt; } radioB.Hide(); if (Q.C != null) { radioC.Text = Q.C.Prompt; } radioC.Hide(); if (Q.D != null) { radioD.Text = Q.D.Prompt; } radioD.Hide(); if (Q.E != null) { radioE.Text = Q.E.Prompt; } radioE.Hide(); }

        public bool Correct
        {
            get
            {
                if (Q == null) return false;
                if (Q.A != null && Q.A.Correct && radioA.Checked) return true;
                if (Q.B != null && Q.B.Correct && radioB.Checked) return true;
                if (Q.C != null && Q.C.Correct && radioC.Checked) return true;
                if (Q.D != null && Q.D.Correct && radioD.Checked) return true;
                if (Q.E != null && Q.E.Correct && radioE.Checked) return true;
                return false;
            }

Where have I gone wrong?

Thank you,

Travis

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio-2010