【发布时间】:2020-09-04 19:23:40
【问题描述】:
我可以在为班级项目设置 Windows 表单测验时使用一些帮助。
namespace WindowsFormsApp7
{
public partial class Form1 : Form
{
//I'm using p to track the amount of points the user collects through the quiz.
int p = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
#region Submit Button & Point Calculation
private void button1_Click(object sender, EventArgs e)
{
//Calculating the amount of point the user collected after submitting his answers.
switch (p)
{
case 1:
radioButton1c.Checked = true;
p++;
break;
case 2:
radioButton2a.Checked = true;
p++;
break;
case 3:
radioButton3b.Checked = true;
p++;
break;
case 4:
radioButton4c.Checked = true;
p++;
break;
case 5:
radioButton5a.Checked = true;
p++;
break;
case 6:
radioButton6a.Checked = true;
p++;
break;
case 7:
radioButton7c.Checked = true;
p++;
break;
case 8:
radioButton8d.Checked = true;
p++;
break;
case 9:
radioButton9a.Checked = true;
p++;
break;
case 10:
radioButton10b.Checked = true;
p++;
break;
}
MessageBox.Show($"You have collected {p} amount of points.");
}
}
}
到目前为止,这就是我的课堂项目。我基本上有一个带有标签的 Visual Studio Windows 窗体和一个带有 4 个单选框的组框。 radioBox1c.Checked = True 是我试图检查是否在该组中检查了该特定的人。然后它转到radiobox"XX".Checked 并做同样的事情。如果选中,它将添加到p。我的问题是我无法运行它,因为我有错误。我试过用很多 if 代替 switch,但我迷路了。显示用户无论选择什么答案都得0分,有什么办法可以解决吗?
【问题讨论】:
-
请用返回的错误更新帖子。
-
抱歉,我发现了问题,我在修改代码时删除了 2 个大括号。我把它们固定在垃圾场对不起。我唯一的问题是 MessageBox.Show($"你已经收集了 {p} 点数。");目前它似乎没有增加 p 的值
标签: c# visual-studio radio-button