zoukankan      html  css  js  c++  java
  • 简易计算器WinForm方式

    在博客园上看到的,忘记路径了

    效果图:

    Form1.cs

    namespace 简易计算器
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private string FuHao;  //定义操作符号(+,-,*,/)
            private string num1;   //定义第一个参数(就是参与运算的第一个数)
            private string num2;   //定义第二个参数
            private string oldValue = "0";   //定义老参数
    
            private void btn_Clean_Click(object sender, EventArgs e)
            {
                txt_Vlaue.Text = "0";
                FuHao = string.Empty;
                oldValue = "0";
            }
    
            private void btn_GetVlaue_Click(object sender, EventArgs e)
            {
                if (FuHao == string.Empty)
                {
                    txt_Vlaue.Text = num1.ToString();
                }
                else
                {
                    GetValue();
                }
            }
    
    
          
    
            private void btn_add_Click(object sender, EventArgs e)
            {
                if (num2 != null && num2 != string.Empty)
                {
                    GetValue();
                }
                FuHao = "+";
                oldValue = "0";
            }
    
            private void btn_Jian_Click(object sender, EventArgs e)
            {
                if (num2 != null && num2 != string.Empty)
                {
                    GetValue();
                }
                FuHao = "-";
                oldValue = "0";
            }
    
            private void btn_Cheng_Click(object sender, EventArgs e)
            {
                if (num2 != null && num2 != string.Empty)
                {
                    GetValue();
                }
                FuHao = "*";
                oldValue = "0";
            }
    
            private void btn_Chu_Click(object sender, EventArgs e)
            {
                if (num2 != null && num2 != string.Empty)
                {
                    GetValue();
                }
                FuHao = "/";
                oldValue = "0";
            }
    
            private void btn_0_Click(object sender, EventArgs e)
            {
                InputName("0");
            }
          
    
            private void btn_1_Click(object sender, EventArgs e)
            {
                InputName("1");
            }
    
            private void btn_2_Click(object sender, EventArgs e)
            {
                InputName("2");
            }
    
            private void btn_3_Click(object sender, EventArgs e)
            {
                InputName("3");
            }
    
            private void btn_4_Click(object sender, EventArgs e)
            {
                InputName("4");
            }
    
            private void btn_5_Click(object sender, EventArgs e)
            {
                InputName("5");
            }
    
            private void btn_6_Click(object sender, EventArgs e)
            {
                InputName("6");
            }
    
            private void bvtn_7_Click(object sender, EventArgs e)
            {
                InputName("7");
            }
    
            private void btn_8_Click(object sender, EventArgs e)
            {
                InputName("8");
            }
    
            private void btn_9_Click(object sender, EventArgs e)
            {
                InputName("9");
            }
    
            public void InputName(string value)
            {
                if (oldValue != "0")
                {
                    txt_Vlaue.Text = oldValue + value;
                }
                else
                {
                    if (value == ".")
                    {
                        txt_Vlaue.Text = "0" + value;
                    }
                    else
                    {
                        txt_Vlaue.Text = value;
                    }
                }
                oldValue = txt_Vlaue.Text;
    
                if (FuHao != null && FuHao.ToString().Trim() != string.Empty)
                {
                    num2 = txt_Vlaue.Text;
                }
                else
                {
                    num1 = txt_Vlaue.Text;
                }
            }
    
    
            private void GetValue()
            {
                double numa = double.Parse(num1);
                double numb = double.Parse(num2);
                double result = 0;
                switch (FuHao)
                {
                    case "+":
                        result = numa + numb;
                        break;
                    case "-":
                        result = numa - numb;
                        break;
                    case "*":
                        result = numa * numb;
                        break;
                    default:
                        result = numa / numb;
                        break;
                }
                txt_Vlaue.Text = result.ToString();
                FuHao = string.Empty;
                oldValue = "0";
                num1 = txt_Vlaue.Text;
                num2 = string.Empty;
            }
        }
    }
  • 相关阅读:
    编译安装centos6.9 php7.0 mysql5.6 nginx1.8
    mysql小细节随笔
    mpdf中文开发使用文档附demo实例
    svn和NetBeans一起使用造成svn老是死锁, database is locked
    Mastering MariaDB 神秘的MariaDB 中文翻译版
    Laravel开发采坑系列问题
    phpspider php爬虫框架
    ajaxFileUpload只能上传一次,和上传同名图片不能上传等bug问题
    bootstrap-treeview 中文开发手册
    phpredis Redis阵列 Redis Arrays
  • 原文地址:https://www.cnblogs.com/hellocjr/p/2923540.html
Copyright © 2011-2022 走看看