C#计算器源码,C#窗体计算器(模拟实体计算器)源码

C#计算器源码,C#窗体计算器(模拟实体计算器)源码
仿真计算器效果图
完整源码下载:https://download.csdn.net/download/angelsapple/14154695
空间名称从上到下排序
textbox:textresult
button 20
数字按钮:num00,num0,—,num9,
小数点:numdot,
Ac:zeroAc,M+:nummc, MR:nummr,
加numplus 减numsub 乘nummul 除numdiv 等于numeq,
result1主要表示运算符之前的数值,result2主要表示运算符之后的数值,最后点击等号按钮,将2个数值进行运算得出结果。

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

namespace c1602
{
    public partial class calculator : Form
    {
        public calculator()
        {
            InitializeComponent();
            
        }
        
        double res1d = 0;
        double jiyizheng = 0;
        double jia = 0;
        double jian = 0;
        double cheng = 0;
        double chu = 0;        
        double yingzi1 = 0;
        double yingzi2 = 0;
        double yingzi3 = 0;
        string result1 = "0";
        string result2 = "0";
        string res1 = "0";
        string res2 = "0";
        string yingzi = "0";
        string snum1 = "1";
        string snum2 = "2";
        string snum3 = "3";
        string snum4 = "4";
        string snum5 = "5";
        string snum6 = "6";
        string snum7 = "7";
        string snum8 = "8";
        string snum9 = "9";
        string snum0 = "0";
        string snum00 = "00";
        string snumdot = ".";
        #region 数字功能键
        private void zeroAc_Click(object sender, EventArgs e)
        {
            result2 = "0";
            textresult.Text = "0";
        }
        private void numdot_Click(object sender, EventArgs e)
        {
                result2 = result2 + snumdot;

        }

        private void num00_Click(object sender, EventArgs e)
        {
            snum00 = result2;
            snum00 = snum00 + "00";
            yingzi3 = double.Parse(snum00);
            snum00 = Convert.ToString(yingzi3);
            result2 = snum00;
            textresult.Text = result2;
        }
        private void num0_Click(object sender, EventArgs e)
        {
            snum0 = result2;
            snum0 = snum0 + "0";
            yingzi3 = double.Parse(snum0);
            snum0 = Convert.ToString(yingzi3);
            result2 = snum0;
            textresult.Text = result2;
        }
        private void num1_Click_1(object sender, EventArgs e)
        {
            snum1 = result2;
            snum1 = snum1+"1";
            yingzi3 = double.Parse(snum1);
            snum1 = Convert.ToString(yingzi3);
            result2 = snum1;
            textresult.Text = result2;
        }
        private void num2_Click(object sender, EventArgs e)
        {
            snum2 = result2;
            snum2 = snum2 + "2";
            yingzi3 = double.Parse(snum2);
            snum2 = Convert.ToString(yingzi3);
            result2 = snum2;
            textresult.Text = result2;
        }
        private void num3_Click(object sender, EventArgs e)
        {
            snum3 = result2;
            snum3 = snum3 + "3";
            yingzi3 = double.Parse(snum3);
            snum3 = Convert.ToString(yingzi3);
            result2 = snum3;
            textresult.Text = result2;
        }

        private void num4_Click(object sender, EventArgs e)
        {
            snum4 = result2;
            snum4 = snum4 + "4";
            yingzi3 = double.Parse(snum4);
            snum4 = Convert.ToString(yingzi3);
            result2 = snum4;
            textresult.Text = result2;
        }

        private void num5_Click(object sender, EventArgs e)
        {
            snum5 = result2;
            snum5 = snum5 + "5";
            yingzi3 = double.Parse(snum5);
            snum5 = Convert.ToString(yingzi3);
            result2 = snum5;
            textresult.Text = result2;
        }

        private void num6_Click(object sender, EventArgs e)
        {
            snum6 = result2;
            snum6 = snum6 + "6";
            yingzi3 = double.Parse(snum6);
            snum6 = Convert.ToString(yingzi3);
            result2 = snum6;
            textresult.Text = result2;
        }

        private void num7_Click(object sender, EventArgs e)
        {
            snum7 = result2;
            snum7 = snum7 + "7";
            yingzi3 = double.Parse(snum7);
            snum7 = Convert.ToString(yingzi3);
            result2 = snum7;
            textresult.Text = result2;
        }

        private void num8_Click(object sender, EventArgs e)
        {
            snum8 = result2;
            snum8 = snum8 + "8";
            yingzi3 = double.Parse(snum8);
            snum8 = Convert.ToString(yingzi3);
            result2 = snum8;
            textresult.Text = result2;
        }

        private void num9_Click(object sender, EventArgs e)
        {
            snum9 = result2;
            snum9 = snum9 + "9";
            yingzi3 = double.Parse(snum9);
            snum9 = Convert.ToString(yingzi3);
            result2 = snum9;
            textresult.Text = result2;
        }

       
        #endregion
        private void nummc_Click(object sender, EventArgs e)
        {
            res1 = textresult.Text;
            res1d = double.Parse(res1);
            jiyizheng = res1d;
        }

       

        private void nummr_Click(object sender, EventArgs e)
        {
            res2 = Convert.ToString(jiyizheng);
            result2 = res2;
            textresult.Text = result2;
        }
        #region 加减乘除等于
        //除法
        private void numdiv_Click(object sender, EventArgs e)
        {
            
            result1 = result2;
            string res1 = result2;
            chu = double.Parse(res1);
            yingzi = "chu";
            textresult.Text = result2;
            res1 = "0";
            result2 = res1;
            
        }
        //乘法
        private void nummul_Click(object sender, EventArgs e)
        {
            result1 = result2;
            string res1 = result2;
            cheng = double.Parse(res1);            
            yingzi = "cheng";
            textresult.Text = res1;
            res1 = "0";
            result2 = res1;
            
        }
        //减法
        private void numsub_Click(object sender, EventArgs e)
        {
            result1 = result2;
            textresult.Text = result2;
            string res1 = result2;
            jian = double.Parse(res1);
            yingzi = "jian";
            textresult.Text = result2;
            res1 = "0";
            result2 = res1; 
            
        }
        //加法
        private void numplus_Click(object sender, EventArgs e)
        {
            result1 = result2;
            string res1 = result2;
            jia = double.Parse(res1);
            yingzi = "jia";
            textresult.Text = res1;
            res1 = "0";
            result2 = res1;
            
        }
        
        //等于
        private void numeq_Click(object sender, EventArgs e)
        {
            string res1 = result2;
            yingzi1 = double.Parse(res1);
            if (yingzi == "jia")
            {
                yingzi2 = jia + yingzi1;
                res2 = Convert.ToString(yingzi2);
                result2 = res2;
                result1 = res2;
                textresult.Text = res2;
            }
            else if
                (yingzi == "jian")
            {
                yingzi2 = jian - yingzi1;
                res2 = Convert.ToString(yingzi2);
                result2 =  res2;
                result1 = res2;
                textresult.Text = res2;
            }
            else if
              (yingzi == "cheng")
            {
                
                yingzi2 = cheng * yingzi1;
                res2 = Convert.ToString(yingzi2);
                result2 = res2;
                result1 = res2;
                textresult.Text = res2;
            }
            else if
            (yingzi == "chu")
            {
                yingzi2 = chu / yingzi1;
                res2 = Convert.ToString(yingzi2);
                result2 = res2;
                result1 = res2;
                textresult.Text = res2;
            }
            #endregion
        }
    }
}
  • 2
    点赞
  • 15
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页
评论

打赏作者

angelsapple

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值