我正在運行包含10個問題的問卷。第一個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();
}
}
您的文章是不明確關於我的問題或者你在問什麼。 – LarsTech
您可以將分數傳遞給每個表單的構造函數 – n1ff
如果您試圖在表單之間共享不斷變化的信息,則可能需要查看C#委託。 – user2867342