网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C#计算器

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 Calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string op;
        double a, b;
        Operat o = new Operat();
        private void btn1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "1";
        }

        private void btn2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
              
            }
            textBox1.Text += "2";
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }textBox1.Text += "3";
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "4";
        }

        private void btn5_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "5";
        }

        private void btn6_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "6";
        }

        private void btn7_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
              
            }
            textBox1.Text += "7";
        }

        private void btn8_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "8";
        }

        private void btn9_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
               
            }
            textBox1.Text += "9";
        }

        private void btn0_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
              
            }
            textBox1.Text += "0";
        }

        private void btnDot_Click(object sender, EventArgs e)
        {
            string s = textBox1.Text;
            if (s.IndexOf('.') > -1)
            {
                MessageBox.Show("已经包含小数点", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else
            {
                textBox1.Text += ".";
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (op == "+" || op == "-" || op == "*" || op == "/")
            {
                op = "+";
            }
            else
            {
                op = "+";
                a = double.Parse(textBox1.Text);
            }
            textBox1.Text = "";
        }

        private void btnSub_Click(object sender, EventArgs e)
        {
            if (op == "+" || op == "-" || op == "*" || op == "/")
            {
                op = "-";
            }
            else
            {
                op = "-";
                a = double.Parse(textBox1.Text);
            }
            textBox1.Text = "";
        }

        private void btnMulti_Click(object sender, EventArgs e)
        {
            if (op == "+" || op == "-" || op == "*" || op == "/")
            {
                op = "*";
            }
            else
            {
                op = "*";
                a = double.Parse(textBox1.Text);
            }
            textBox1.Text = "";
        }

        private void btnDiv_Click(object sender, EventArgs e)
        {
            if (op == "+" || op == "-" || op == "*" || op == "/")
            {
                op = "/";
            }
            else
            {
                op = "/";
                a = double.Parse(textBox1.Text);
            }
            textBox1.Text = "";
        }

        private void btnResult_Click(object sender, EventArgs e)
        {
            b = double.Parse(textBox1.Text);
            textBox1.Text = o.Operation(a, b, op).ToString();

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }

        private void btnBackspace_Click(object sender, EventArgs e)
        {
            string sub = textBox1.Text;
            textBox1.Text = sub.Substring(0, sub.Length - 1);
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (textBox1.Text == "0")
            {
                textBox1.Text = "";
            }

            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar) && e.KeyChar != '.')
            {
                e.Handled = true;
            }
           

        }


    }

    public class Operat
    {
        public Double Operation(double a, double b, string o)
        {
            double r = 0; ;
            switch (o)
            {
                case "+":
                    r = a + b;
                    break;
                case "-":
                    r = a - b;
                    break;
                case "*":
                    r = a * b;
                    break;
                case "/":
                    r = a / b;
                    break;
            }
            return r;

        }

    }
}
 


分享标题:C#计算器
URL地址:http://bjjierui.cn/article/joiscj.html

其他资讯