1 using System.Windows.Forms; 2 3 namespace 计应142 王斌 4 { 5 public partial class Form1 : Form 6 { 7 public static int Count = 0; 8 public static int right = 0; 9 public static int fault = 0; 10 public Form1() 11 { 12 InitializeComponent(); 13 } 14 15 private void button4_Click(object sender, EventArgs e) 16 { 17 label2.Text = "/"; 18 RandomNum(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 label2.Text = "+"; 24 RandomNum(); 25 } 26 27 private void button2_Click(object sender, EventArgs e) 28 { 29 label2.Text = "-"; 30 RandomNum(); 31 } 32 private void button3_Click(object sender, EventArgs e) 33 { 34 label2.Text = "*"; 35 RandomNum(); 36 } 37 38 private void RandomNum() 39 { 40 Random ran = new Random(); 41 int n1, n2; 42 n1 = ran.Next(1, 11); 43 n2 = ran.Next(1, 11); 44 textBox1.Text = n1.ToString(); 45 textBox2.Text = n2.ToString(); 46 textBox3.Text = ""; 47 Count++; 48 } 49 50 51 private void button6_Click(object sender, EventArgs e) 52 { 53 54 textBox3.Enabled = false; 55 Form2 frm2 = new Form2(); 56 frm2.ShowDialog(); 57 58 } 59 private void textBox3_KeyDown(object sender, KeyEventArgs e) 60 { 61 { 62 if (e.KeyCode == Keys.Enter) 63 { 64 if (textBox3.Text == textBox3.ToString()) 65 66 right++; 67 68 RandomNum(); 69 } 70 else 71 { 72 fault++; 73 RandomNum(); 74 } 75 int m; 76 string i = label2.Text; 77 switch (i) 78 { 79 case "+": 80 m = int.Parse(textBox1.Text) + int.Parse(textBox2.Text); 81 break; 82 case "-": 83 m = int.Parse(textBox1.Text) - int.Parse(textBox2.Text); 84 break; 85 case "*": 86 m = int.Parse(textBox1.Text) * int.Parse(textBox2.Text); 87 break; 88 case "/": 89 m = int.Parse(textBox1.Text) / int.Parse(textBox2.Text); 90 break; 91 } 92 93 94 95 } 96 } 97 98 private void button5_Click(object sender, EventArgs e) 99 { 100 RandomNum(); 101 } 102 103 } 104 }
为何结果栏里只能写一个数字,而且写上一个数字就会随机出现一组计算,代码试着改了很多处也找不到问题在哪,虽然解决过一次但是
Form2里的错误个数又不能统计了(正确个数也不能统计),好纠结啊。
如果不改现在的正确个数又不能统计了,要崩溃了。
不过比昨天的好一些了,但是还是做不到很成功。