zoukankan      html  css  js  c++  java
  • 计算器

    代码实现:

    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 Chapter7_8

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

            private void Form1_Load(object sender, EventArgs e)

            {

            }

            public static int count = 0;//题目总数

            public static int right = 0;//正确的题目总数

            private void button1_Click(object sender, EventArgs e)

            {

              

                Random();

            }

    //产生1-10的随机数

            private void Random()

            {

                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="";

                count++;

             }

    //当按下回车键表示输入结果

            private void textBox3_KeyDown(object sender, KeyEventArgs e)

            {

                int count;

                string c = label2.Text;

                switch (c)

                {

                    case "+":

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

                        break;

                    case "-":

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

                        break;

                    case "x":

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

                        break;

                    default:

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

                        break;

                      }

                        if (e.KeyCode == Keys.Enter)

                        {

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

                                right++;

                            Random();

                        }

                }

            private void button2_Click(object sender, EventArgs e)

            {

                textBox3.Enabled = false;

                Form2 frm2 = new Form2();

                frm2.ShowDialog();

            }

            private void button3_Click(object sender, EventArgs e)

            {

                label2.Text = "+";

                Random();

            }

            private void button4_Click(object sender, EventArgs e)

            {

                label2.Text = "-";

                Random();

            }

            private void button5_Click(object sender, EventArgs e)

            {

                label2.Text =" *";

                Random();

            }

            private void button6_Click(object sender, EventArgs e)

            {

                label2.Text = "/";

                Random();

            }

            }

            

        }

    //Form2窗体代码编写

    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 Chapter7_8

    {

    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() + "%";

    }

    计算器样式:

  • 相关阅读:
    如何用Python实现网络请求库中的UR解析器,面试必学
    为什么有人说 Python 多线程是鸡肋?
    router-view 与 动态组件 区别
    keep-alive
    vue 客户端渲染和服务端渲染
    js 数组对象深拷贝
    vue template标签
    Jquery中的日历插件
    HTML5中的canvas基本概念及绘图
    HTML5中的音视频处理
  • 原文地址:https://www.cnblogs.com/lixinzhen/p/4856301.html
Copyright © 2011-2022 走看看