码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2015-10-07 22:46:46      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

 

 

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

        
    }
}

技术分享技术分享

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

四则运算

标签:

原文地址:http://www.cnblogs.com/kanghehe/p/4859588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!