C# 隐藏/显示问卷应用程序上的单选按钮
我正在做一项作业,包括创建一个简单的测验类型表单应用程序。然而,每当我运行这个程序时,对于一个多重问题,只有第一个答案会显示出来,我一辈子都不知道为什么 这是CONSTRUCTOR:C# 隐藏/显示问卷应用程序上的单选按钮,c#,winforms,C#,Winforms,我正在做一项作业,包括创建一个简单的测验类型表单应用程序。然而,每当我运行这个程序时,对于一个多重问题,只有第一个答案会显示出来,我一辈子都不知道为什么 这是CONSTRUCTOR: MultipleChoice dlg = new MultipleChoice( new Question("What is the capital of Zimbabwe?", new Answer("Paris", false), new
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
之后没有任何选项:
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();