四则运算
1 partial class Form2 2 { 3 /// <summary> 4 /// Required designer variable. 5 /// </summary> 6 private System.ComponentModel.IContainer components = null; 7 8 /// <summary> 9 /// Clean up any resources being used. 10 /// </summary> 11 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 12 protected override void Dispose(bool disposing) 13 { 14 if (disposing && (components != null)) 15 { 16 components.Dispose(); 17 } 18 base.Dispose(disposing); 19 } 20 21 #region Windows Form Designer generated code 22 23 /// <summary> 24 /// Required method for Designer support - do not modify 25 /// the contents of this method with the code editor. 26 /// </summary> 27 private void InitializeComponent() 28 { 29 this.label1 = new System.Windows.Forms.Label(); 30 this.label2 = new System.Windows.Forms.Label(); 31 this.label3 = new System.Windows.Forms.Label(); 32 this.textBox1 = new System.Windows.Forms.TextBox(); 33 this.textBox2 = new System.Windows.Forms.TextBox(); 34 this.textBox3 = new System.Windows.Forms.TextBox(); 35 this.SuspendLayout(); 36 // 37 // label1 38 // 39 this.label1.AutoSize = true; 40 this.label1.Location = new System.Drawing.Point(34, 46); 41 this.label1.Name = "label1"; 42 this.label1.Size = new System.Drawing.Size(41, 12); 43 this.label1.TabIndex = 0; 44 this.label1.Text = "总计:"; 45 // 46 // label2 47 // 48 this.label2.AutoSize = true; 49 this.label2.Location = new System.Drawing.Point(32, 112); 50 this.label2.Name = "label2"; 51 this.label2.Size = new System.Drawing.Size(41, 12); 52 this.label2.TabIndex = 1; 53 this.label2.Text = "正确:"; 54 // 55 // label3 56 // 57 this.label3.AutoSize = true; 58 this.label3.Location = new System.Drawing.Point(34, 169); 59 this.label3.Name = "label3"; 60 this.label3.Size = new System.Drawing.Size(53, 12); 61 this.label3.TabIndex = 2; 62 this.label3.Text = "正确率:"; 63 // 64 // textBox1 65 // 66 this.textBox1.Enabled = false; 67 this.textBox1.Location = new System.Drawing.Point(135, 46); 68 this.textBox1.Name = "textBox1"; 69 this.textBox1.Size = new System.Drawing.Size(100, 21); 70 this.textBox1.TabIndex = 3; 71 // this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); 72 // 73 // textBox2 74 // 75 this.textBox2.Enabled = false; 76 this.textBox2.Location = new System.Drawing.Point(135, 103); 77 this.textBox2.Name = "textBox2"; 78 this.textBox2.Size = new System.Drawing.Size(100, 21); 79 this.textBox2.TabIndex = 4; 80 // 81 // textBox3 82 // 83 this.textBox3.Enabled = false; 84 this.textBox3.Location = new System.Drawing.Point(135, 169); 85 this.textBox3.Name = "textBox3"; 86 this.textBox3.Size = new System.Drawing.Size(100, 21); 87 this.textBox3.TabIndex = 5; 88 // 89 // Form2 90 // 91 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 92 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 93 this.ClientSize = new System.Drawing.Size(292, 266); 94 this.Controls.Add(this.textBox3); 95 this.Controls.Add(this.textBox2); 96 this.Controls.Add(this.textBox1); 97 this.Controls.Add(this.label3); 98 this.Controls.Add(this.label2); 99 this.Controls.Add(this.label1); 100 this.Name = "Form2"; 101 this.Text = "测试结果"; 102 this.Load += new System.EventHandler(this.Form2_Load); 103 this.ResumeLayout(false); 104 this.PerformLayout(); 105 106 } 107 108 #endregion 109 110 private System.Windows.Forms.Label label1; 111 private System.Windows.Forms.Label label2; 112 private System.Windows.Forms.Label label3; 113 private System.Windows.Forms.TextBox textBox1; 114 private System.Windows.Forms.TextBox textBox2; 115 private System.Windows.Forms.TextBox textBox3; 116 }
1 public partial class Form1 : Form 2 { 3 public Form1() 4 { 5 InitializeComponent(); 6 } 7 public static int Count = 0; 8 public static int right = 0; 9 10 private void Form1_Load(object sender, EventArgs e) 11 { 12 13 } 14 15 private void button1_Click(object sender, EventArgs e) 16 { 17 18 RandomNum(); 19 } 20 private void RandomNum() 21 { 22 Random ran = new Random(); 23 int n1, n2; 24 n1 = ran.Next(1, 11); 25 n2 = ran.Next(1, 11); 26 textBox1.Text = n1.ToString(); 27 textBo2.Text = n2.ToString(); 28 textBox3.Text = ""; 29 Count++; 30 } 31 32 33 34 35 private void button2_Click(object sender, EventArgs e) 36 { 37 textBox3.Enabled = false; 38 Form2 frm2 = new Form2(); 39 frm2.ShowDialog(); 40 } 41 private void 加号_Click(object sender, EventArgs e) 42 { 43 label1.Text = "+"; 44 45 RandomNum(); 46 47 } 48 49 private void 减_Click(object sender, EventArgs e) 50 { 51 label1.Text = "-"; 52 RandomNum(); 53 } 54 55 private void 乘_Click(object sender, EventArgs e) 56 { 57 label1.Text = "*"; 58 RandomNum(); 59 } 60 61 private void 除_Click(object sender, EventArgs e) 62 { 63 label1.Text = "/"; 64 RandomNum(); 65 } 66 67 private void textBox3_KeyDown(object sender, KeyEventArgs e) 68 { 69 int c; 70 string i = label1.Text; 71 switch (i) 72 { 73 case "+": 74 c = int.Parse(textBox1.Text) +int.Parse (textBo2.Text); 75 break; 76 77 case "-": 78 c = int.Parse(textBox1.Text) -int.Parse (textBo2.Text); 79 break; 80 case "*": 81 c = int.Parse(textBox1.Text) *int .Parse (textBo2.Text); 82 break; 83 84 case "/": 85 c = int.Parse(textBox1.Text) /int.Parse (textBo2.Text); 86 break; 87 } 88 if (e.KeyCode == Keys.Enter) 89 { 90 if (textBox3.Text == i.ToString()) 91 right++; 92 RandomNum(); 93 } 94 } 95 96 97 98 } 99 }
实在是 能力有限,只能做成这样了。这个还好是c#中讲过的加法测试,参照着课本做下来一些,但还是有些正确率显示不出来,不知道怎么做,希望老师可以指导下。
以后还会继续努力争取做的更好