繁体   English   中英

隐藏/显示问卷应用程序上的单选按钮

[英]Hide/Show radio buttons on a questionnaire application

我正在做一个涉及创建一个简单的测验类型表单应用程序的任务。 但是,每当我运行该程序时,只有第一个答案显示了一个多个问题,我不能为我的生活找出原因。

这是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");
}

这是问题表格代码:

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;
    }
}

我哪里出错了?

A之后没有任何else选择:

if (Q.B != null) 
{ 
    radioB.Text = Q.B.Prompt; 
} 
radioB.Hide();  //This is **always** going to be called - hiding radioB :)

应该:

if (Q.B != null) 
    radioB.Text = Q.B.Prompt; 
else
    radioB.Hide(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM