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;
            }
        }
    }
  • 相关阅读:
    BZOJ.4842.[NEERC2016]Delight for a Cat(费用流)
    LOJ.6060.[2017山东一轮集训Day1/SDWC2018Day1]Set(线性基)
    BZOJ.5319.[JSOI2018]军训列队(主席树)
    BZOJ.4212.神牛的养成计划(Trie 可持久化Trie)
    HDU.5385.The path(构造)
    HDU.4903.The only survival(组合 计数)
    Codeforces.1043F.Make It One(DP 容斥)
    BZOJ.5110.[CodePlus2017]Yazid 的新生舞会(线段树/树状数组/分治)
    洛谷.3676.小清新数据结构题(树链剖分 树状数组)
    BZOJ.4598.[SDOI2016]模式字符串(点分治 Hash)
  • 原文地址:https://www.cnblogs.com/hellocjr/p/2923540.html
Copyright © 2011-2022 走看看