• winform计算器


    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 FirstForm
    {
        public partial class JiSuanQi : Form
        {
            public JiSuanQi()
            {
                InitializeComponent();
            }
    
            private double sum=0;
            private string biaodashi;
            private string Preyunsuanfu;//存放之前的运算符
            private bool isok=true;//用来判断是否刚刚点过运算符
    
            private void btnling_Click(object sender, EventArgs e)
            {
                Button btn = (Button)sender;
                if (isok)//是否点击过运算符
                {
                    txtshuru.Text = btn.Text;
                    //isok = false;
                }
                else
                {
                    txtshuru.Text += btn.Text;
                }
    
            }
    
            private void btnjia_Click(object sender, EventArgs e)
            {
                Button btn = (Button)sender;
                string yunsuanfu = btn.Text;
                if (Preyunsuanfu == null)
                {
                    biaodashi = txtshuru.Text;//“+”可以去掉
                    sum = double.Parse(txtshuru.Text);
                }
                else
                {
                    if (!isok)
                    {
                        if (Preyunsuanfu == "+")
                        {
                            sum += double.Parse(txtshuru.Text);
                        }
                        if (Preyunsuanfu == "-")
                        {
                            sum -= double.Parse(txtshuru.Text);
                        }
                        if (Preyunsuanfu == "*")
                        {
                            sum *= double.Parse(txtshuru.Text);
                        }
                        if (Preyunsuanfu == "/")
                        {
                            sum /= double.Parse(txtshuru.Text);
                        }
                        if (Preyunsuanfu == "%")
                        {
                            sum %= double.Parse(txtshuru.Text);
                        }
    
                        biaodashi = biaodashi+ Preyunsuanfu + txtshuru.Text;
                        txtshuru.Text = sum.ToString();
                    } 
                }
                txtjisuanshi.Text = biaodashi + yunsuanfu;
                Preyunsuanfu = yunsuanfu;
                isok = true;
                
            }
    
            private void btnClear_Click(object sender, EventArgs e)
            {
    
            }
    
            private void btndeng_Click(object sender, EventArgs e)
            {
    
            }
    
        }
    }
  • 相关阅读:
    node.js之npm命令安装扩展模块
    jquery选择器(转)
    node.js入门
    node.js之模块
    redhat 下装redis
    html 5之websocket(转)
    node.js安装和环境搭建
    javascript 动态加载脚本库
    HTML5 LocalStorage 本地存储
    【ecmascript】 ECMAScript 6概览【转】
  • 原文地址:https://www.cnblogs.com/dlexia/p/4648971.html
Copyright © 2020-2023  润新知