四则运算

 

namespace Chapter四则运算

{    

public partial class Form1 : Form

    {  

       public Form1()        

        {  

           InitializeComponent();

        }

        public static int Count = 0;

        private int t = 60;

        public static int right = 0;

        private void button1_Click_1(object sender, EventArgs e)

        {

            label4.Text = t.ToString();

            timer1.Enabled = true;

            timer1.Interval = 1000;

            timer1.Start();

            RandomNum();

        }

               private void RandomNum()

        {

            Random ran = new Random();

            int n1, n2;  

           n1 = ran.Next(1, 11);

            n2 = ran.Next(1, 11);

            textBox1.Text = n1.ToString();

            textBox2.Text = n2.ToString();

            textBox3.Text = "";       

        }

        private void timer1_Tick(object sender, EventArgs e)

        {

            if (t <= 0)

            {

                timer1.Enabled = false;

                textBox3.Enabled = false;

                MessageBox.Show("时间到!");

                textBox3.Enabled = false;

                Form2 frm2 = new Form2();

                frm2.ShowDialog();

            }

            t = t - 1;

            label4.Text = t.ToString();

        }

     

        private void button3_Click(object sender, EventArgs e)

        {

            label1.Text = "+";

        }

        private void button4_Click(object sender, EventArgs e)  

       {

            label1.Text = "-";

        }

        private void button5_Click(object sender, EventArgs e)

        {

            label1.Text = "*";

        }

        private void button6_Click_1(object sender, EventArgs e)

        {

            label1.Text = "/";  

       }

        private void textBox3_KeyDown_1(object sender, KeyEventArgs e)  

       {

            int sum;

            string m = label1.Text;

            switch (m)

            {

                case "+":

                    sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);

                    break;

                case "-":

                    sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);

                    break;

                case "*":

                    sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);

                    break;

                default:   

                  sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);

                    break;

            }

            if (e.KeyCode == Keys.Enter)

            {

                if (textBox3.Text == sum.ToString())

                {

                    right++;  

                   Count++;

                    RandomNum();

                  }

                else

                    Count++;

                RandomNum();

 

 

            }

        }

        private void button2_Click_1(object sender, EventArgs e)

        {

            textBox3.Enabled = false;  

           Form2 frm = new Form2();  

           frm.ShowDialog();

        }

   }

}

 

      

  总结:

      C#书上有一个让做加法的编程,当看到第二次作业时感觉可以类比着做,开始做,

的确遇到了困难,不知从何做起,平时也只是按照书敲敲代码,也不怎么明白。当同学

们陆续上交作业后,我查看了,找到了思路,自己试着慢慢做,查了书上的代码,最终

成功完成了,虽然这次有部分是参考别人的才完成的,不过能学以自用,变成自己的感

觉也是棒棒哒!在做这道作业的过程中也学到了不少知识,感觉到了编程的奇妙。以后

要加油了,希望下次能独立完成老师布置的作业!

posted @ 2015-10-01 15:14  青春如诗,你如画  阅读(215)  评论(2编辑  收藏  举报