[英]Windows form Quiz tracking radio buttons
我可以使用一些帮助来为 class 项目设置 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.");
}
}
}
到目前为止,这就是我为 class 项目所拥有的。 我基本上有一个带有 label 的视觉工作室 windows 表格和一个带有 4 个单选框的组合框。 radioBox1c.Checked = True
是我试图检查那个特定的人是否在该组中被选中。 然后它移动到radiobox"XX"
.Checked 并做同样的事情。 如果它被选中,它将添加到p
。 我的问题是我无法运行它,因为我有错误。 我尝试过使用很多if
而不是 switch 但我迷路了。 它显示无论选择什么答案,用户都获得 0 分,有什么办法可以解决吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
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)
{
}
private void button1_Click(object sender, EventArgs e)
{
//Calculating the amount of point the user collected after submitting his answers.
if (radioButton1c.Checked == true)
{
p++;
}
if (radioButton2a.Checked == true)
{
p++;
}
if (radioButton3b.Checked == true)
{
p++;
}
if (radioButton4c.Checked == true)
{
p++;
}
if (radioButton5a.Checked == true)
{
p++;
}
if (radioButton6a.Checked == true)
{
p++;
}
if (radioButton7c.Checked == true)
{
p++;
}
if (radioButton8d.Checked == true)
{
p++;
}
if (radioButton9a.Checked == true)
{
p++;
}
if (radioButton10b.Checked == true)
{
p++;
}
MessageBox.Show($"You have earned {p} point(s).");
Application.Exit();
}
}
}
设法解决了我自己的问题。 我继续使用 if 而不是开关,一切似乎都正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.