public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int Count = 0; public static int right = 0; public static int fault = 0; private void button1_Click(object sender, EventArgs e) { RandomNum(); } private void RandomNum() { Random ran = new Random(); int n1, n2; n1 = ran.Next(1, 10); n2 = ran.Next(1, 10); textBox1.Text = n1.ToString(); textBox2.Text = n2.ToString(); textBox3.Text = ""; Count++; } private void timer1_Tick(object sender, EventArgs e) { { textBox3.Enabled = false; textBox3.Enabled = false; Form2 frm = new Form2(); frm.ShowDialog(); } } private void textBox3_KeyDown(object sender, KeyEventArgs e) { int sum; sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text); if (e.KeyCode == Keys.Enter) { if (textBox3.Text == sum.ToString()) right++; RandomNum(); } } private void button2_Click(object sender, EventArgs e) { textBox3.Enabled = false; Form2 frm2 = new Form2(); frm2.ShowDialog(); } private void button3_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void label3_Click_1(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void label5_Click(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { textBox1.Text = Form1.Count.ToString(); textBox2.Text = Form1.right.ToString(); textBox3.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%"; } private void label1_Click(object sender, EventArgs e) { textBox1.Text = Form1.Count.ToString(); textBox2.Text = Form1.fault.ToString(); } private void label2_Click(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } }
虽然费了很长时间写好了,但是还是有些小毛病,可能还是我学的不够好吧,希望以后会更加好好学习,做的更完美些
时间: 2024-10-12 13:35:05