四则运算

 

 

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

namespace 计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }
        int a, b,sum;
        public static int count = 0;
        public static int right = 0;

        private void button1_Click(object sender, EventArgs e)
        {
            an();
        }
        private void an()
        {
            Random shu = new Random();
            a = shu.Next(1, 11);
            b = shu.Next(1, 11);
            textBox1.Text = a.ToString();
            textBox2.Text = b.ToString();
            textBox4.Text = "";

        }

        private void jia_Click(object sender, EventArgs e)
        {
            
           
            sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
          
          
        }

        private void jian_Click(object sender, EventArgs e)
        {
            
            sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
           
          
        }

        private void cheng_Click(object sender, EventArgs e)
        {
            
            sum = int.Parse(textBox1.Text) *int.Parse(textBox2.Text);
           
           
        }

        private void chu_Click(object sender, EventArgs e)
        {
            
            sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
            
          
           
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ShowDialog();
            
        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox4.Text == sum.ToString())
                {
                    right++;
                }
                count++;
            }
            an();
        }

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

namespace 计算器
{
    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();
        }

        
    }
}

老实说,做完这篇代码之后,头都是大的。实在不易!!

posted on 2015-10-07 21:37  你以为我是谁  阅读(115)  评论(1)    收藏  举报