运算

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace xia

{    

public partial class Form1 : Form   

  {     

    public Form1()        

{          

   InitializeComponent();       

  }      

   public static int count = 0;     

    public static int right = 0;  

       private void button5_Click(object sender, EventArgs e)     

    {           

  Random ab = new Random();       

      int a, b;         

    a = ab.Next(1, 11);      

       b = ab.Next(1, 11);        

     textBox1.Text = a.ToString();         

    textBox2.Text = b.ToString();    

         textBox3.Text = "";       

      count++;   

      }

        private void button1_Click(object sender, EventArgs e)       

  {             label1.Text = "+";         }

        private void button2_Click(object sender, EventArgs e)       

  {             label1.Text = "-";         }

        private void button3_Click(object sender, EventArgs e)     

    {             label1.Text = "*";         }

        private void button4_Click(object sender, EventArgs e)    

     {             label1.Text = "/";         }

        private void textBox3_KeyDown(object sender, KeyEventArgs e)    

     {      

       int sum;         

    if (label1.Text == "+")          

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

         if (label1.Text == "-")                

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

           if (label1.Text == "*")                      

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

          if (label1.Text == "/")          

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

     if (e.KeyCode==Keys.Enter)    

         {            

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

      {                     count++;             

                             right++;          

       }             

    else                 

    count++;             }     

    }

        private void button6_Click(object sender, EventArgs e)      

   {        

     textBox3.Enabled = false;       

      Form2 frm2 = new Form2();       

      frm2.Show();    

     }  

   }

}

 

 

 

namespace xia

{  

   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();        

     textBox3.Text = ((Form1.right / (double)(Form1.count)) * 100) + ToString() + "%";      

   }    

}

}

posted @ 2015-10-03 11:20  夏yongyong  阅读(152)  评论(0编辑  收藏  举报