C#计算器-创新互联-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

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;

创新互联公司是专业的阿城网站建设公司,阿城接单;提供网站制作、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行阿城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

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;

       }

   }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


本文题目:C#计算器-创新互联
网站链接:http://kswsj.cn/article/ccooij.html

其他资讯