【发布时间】:2016-04-05 15:09:49
【问题描述】:
我正在做一份包含 10 个问题的问卷。 First Form.cs 只是开始按钮,在新的 Form.cs 中打开第一个问题。
新表单有 3 个单选按钮,每个按钮应返回不同的点(0、5、10)。这些点应在所有表单中累积,然后应在最终的 Form.cs 中显示总数或上传到 SQL 等。
我尝试过编写代码,但不确定这是最好的方式。
namespace XX
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
int points;
int totalscore = 0;
private void btnCANCEL_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void zeropoint_CheckedChanged(object sender, EventArgs e)
{
if (zeropoint.Checked == true)
{
points = 0;
totalscore = totalscore + points;
}
}
private void fivepoint_CheckedChanged(object sender, EventArgs e)
{
if (fivepoint.Checked == true)
{
points = 5;
totalscore = totalscore + points;
}
}
private void tenpoint_CheckedChanged(object sender, EventArgs e)
{
if (tenpoint.Checked == true)
{
points = 10;
totalscore = totalscore + points;
}
}
Form3 thirdForm = new Form3();
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Hide();
var form3 = new Form3();
form3.FormClosed += (s, args) => this.Close();
form3.Show();
}
}
【问题讨论】:
-
你的帖子不清楚问题是什么或你在问什么。
-
您可以将分数传递给每个表单的构造函数
-
如果您尝试在表单之间共享不断变化的信息,您可能需要查看 C# 委托。