using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 计算 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int count = 0; public static int right = 0; int a, b; private void button2_Click(object sender, EventArgs e) { an(); } private void button3_Click(object sender, EventArgs e) { string z = textBox3.Text; string s = textBox4.Text; int q = int.Parse(s); if (z == "+") { if (q == a + b) { right++; } count++; } if (z == "-") { if (q == a - b) { right++; } count++; } if (z == "*") { if (q == a * b) { right++; } count++; } if (z == "/") { if (q == a / b) { right++; } count++; } an(); } private void an() { Random shu=new Random(); a=shu.Next(1,11); b=shu.Next(1,11); textBox1.Text = a.ToString(); textBox2.Text = b.ToString(); textBox3.Text = ""; textBox4.Text = ""; } private void button1_Click_1(object sender, EventArgs e) { Form2 da = new Form2(); da.ShowDialog(); } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 计算 { 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(); } } }
总结:
这次写这代码,感觉自己对这掌握这方面的知识还是太少。
自己预计两个小时完成 结果用了三个多小时才完成,自己应该多去掌握这方面知识以此来缩短编写的时间,并且也不会在编写时出现那么多错误,自己以后多学习这方面知识。