标签:
namespace JiSuanQi { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int Count = 0; public static int Right = 0; private void RandomNum() { Random rad = new Random(); int m1,m2; m1 = rad.Next (1,101); m2 = rad.Next (1,101); textBox1 .Text = m1 .ToString (); textBox2 .Text = m2 .ToString (); textBox3 .Text = ""; Count ++; } private void jisuan() { Random js = new Random(); int a, b; a = js.Next(11); b = js.Next(11); textBox1.Text = a.ToString(); textBox2.Text = b.ToString(); Count++; } private void textBox4_KeyDown(object sender, KeyEventArgs e) { string fuhao; fuhao = textBox4.Text; if (fuhao == "+") { lable1.Text = "+"; } else if (fuhao == "-") { lable1.Text = "-"; } else if (fuhao == "*") { lable1.Text = "*"; } else { label0.Text = "/"; } } private void button1_Click(object sender ,EventArgs e) { jisuan (); } private void textBox3_KeyDown(object sender,EventArgs e) { int txt3; if (textBox4.Text == "+") { txt3 = int.Parse (textBox1.Text )+int.Parse (textBox2 .Text ); } else if (textBox4.Text == "-") { txt3 = int.Parse (textBox1.Text )-int.Parse (textBox2 .Text ); } else if (textBox4.Text == "*") { txt3 = int.Parse (textBox1.Text )*int.Parse (textBox2 .Text ); } else { txt3 = int.Parse (textBox1.Text )/int.Parse (textBox2 .Text ); } if (e.KeyCode == Keys .Enter ) { if(textBox3 .Text ==txt3 .ToString ()) { right++; textBox3 .Text =""; jisuan (); } } } } } } namespace JiSuanQi { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { textBox3.Enabled = false; new Form2().ShowDialog(); } 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) / (double)(Form1.Count)) * 100).ToString() + "%"; } } }
运行结果:
总结:
我做的是窗体程序,我觉得窗体程序比较简单,控制台程序不知道从哪里入手。我做的这个程序耗时比较多,用了5个多小时,以前在上C#课时候,练习过加法训练,我本来以为会很简单很快地做出来,可是在做的时候做了无数次测试才成功,所以,我觉得还是我平时练习的不够多,所以我以后会勤加练习的。
标签:
原文地址:http://www.cnblogs.com/LTING/p/4854743.html