1
我一直在爲學校的程序工作,我正嘗試使用構造函數在C#中的窗體之間傳輸字符串。我以前使用的方法在從1轉換爲2時工作,但現在無法將form2轉換爲3.代碼用於10個問題的數學測驗。由於通過構造函數傳輸字符串。錯誤
public Form2()
{
InitializeComponent();
}
public Form2(string name, string age)
{
InitializeComponent();
int Score;
int QNUM;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button1_Click(int answer, string name, string age, int score, int QNUM, object sender, EventArgs e)
{
if (age == "Year 3")
{
Random rnd = new Random();
int Number1 = rnd.Next(1, 51);
int Number2 = rnd.Next(1, 51);
int Answer = Number1 + Number2;
label4.Text = Convert.ToString(Number1 + " + " + Number2);
}
if(textBox1.Text == Convert.ToString(answer))
{
score = score + 1;
}
if (textBox1.Text == Convert.ToString(answer))
{
score = score + 1;
}
QNUM = QNUM + 1;
label2.Text = Convert.ToString(QNUM);
if (QNUM == 1)
{
button1.Text = "Next";
}
if (QNUM == 9)
{
button1.Text = "Finish";
}
if (QNUM == 11)
{
Form3 Name2 = new Form3 (name, score);
Name2.Show();
}
}
}
}
我也已經把代碼中的第三種形式
public Form3()
{
InitializeComponent();
}
public Form3(string name, string score)
{
InitializeComponent();
{
}
}