• 简单计算器


    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 计算器
    {
        public partial class 简单计算器 : Form
        {
            public 简单计算器()
            {
                InitializeComponent();
            }
            string one="";
            string tow="";
            char caozuo;
            double one1;
            double tow1;
            int biaoji = 1;
            private void button6_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "6";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "6";
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "7";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text+= "7";
            }
    
            private void 简单计算器_Load(object sender, EventArgs e)
            {
                this.KeyPreview = true;
                this.richTextBox1.Text= "";
                
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "8";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "8";
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "9";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "9";
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "4";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "4";
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "5";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "5";
            }
    
            private void button8_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "1";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "1";
            }
    
            private void button9_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "2";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "2";
            }
    
            private void button7_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "3";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "3";
            }
            //加减乘除
            private void button16_Click(object sender, EventArgs e)
            {
                caozuo = '+';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "+";
            }
            private void button24_Click(object sender, EventArgs e)
            {
                caozuo = 's';
                one = this.richTextBox1.Text;        
            }
            private void button22_Click(object sender, EventArgs e)
            {
                caozuo = 'c';
                one = this.richTextBox1.Text;
               
    
            }
            private void button25_Click(object sender, EventArgs e)
            {
                caozuo = 't';
                one = this.richTextBox1.Text;
               
            }
            private void button27_Click(object sender, EventArgs e)
            {
                caozuo = 'l';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "log10";
            }
            private void button15_Click(object sender, EventArgs e)
            {
                caozuo = '×';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "×";
            }
    
            private void button14_Click(object sender, EventArgs e)
            {
                caozuo = '÷';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "÷";
            }
    
            private void button13_Click(object sender, EventArgs e)
            {
                caozuo = '-';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "-";
            }
            private void button19_Click(object sender, EventArgs e)
            {
                caozuo = '%';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "%";
            }
            private void button20_Click(object sender, EventArgs e)
            {
                caozuo = '√';
                one = this.richTextBox1.Text;
                this.richTextBox1.Text += "√";
            }
            //加减乘除%X^2;
            private void button11_Click(object sender, EventArgs e)//=
            {      if (caozuo == '√')
                {
                    biaoji = 0;
                    one1 = Convert.ToDouble(one);
                    this.richTextBox1.Text += "
    ";
                    this.richTextBox1.Text += (Math.Sqrt(one1)).ToString();
                }
                else if (caozuo == 's')
                {
                    biaoji = 0;
                    one1 = Convert.ToDouble(one);
                    double t;
                    t = 180 / one1;
                    this.richTextBox1.Text += "
    ";
                    this.richTextBox1.Text += (Math.Sin(Math.PI /t)).ToString();
                }else if (caozuo == 't')
                {
                    biaoji = 0;
                    one1 = Convert.ToDouble(one);
                    double t;
                     t= 180/one1;
                    this.richTextBox1.Text += "
    ";
                    this.richTextBox1.Text += (Math.Tan(Math.PI/t)).ToString();
                }else if (caozuo == 'c')
                {
                    biaoji = 0;
    
                    one1 = Convert.ToDouble(one);
                    double t;
                    t = 180 / one1;
                    this.richTextBox1.Text += "
    ";
                    this.richTextBox1.Text += (Math.Cos(Math.PI / t)).ToString();
                }else if (caozuo == 'l')
                {
                    biaoji = 0;
                    one1 = Convert.ToDouble(one);
                    this.richTextBox1.Text += "
    ";
                    this.richTextBox1.Text += (Math.Log10(one1)).ToString();
                }
                else{
    
                    int t;
                    biaoji = 0;
                    tow = this.richTextBox1.Text;
                    t = (tow.Length - one.Length) - 1;
                    tow = tow.Substring(tow.Length - t);
                    one1 = Convert.ToDouble(one);
                    tow1 = Convert.ToDouble(tow);
                    if (caozuo == '+')
                    {
                        this.richTextBox1.Text += "
    ";
                        this.richTextBox1.Text += (one1 + tow1).ToString();
    
                    }
                    else if (caozuo == '×')
                    {
                        this.richTextBox1.Text += "
    ";
                        this.richTextBox1.Text += (one1 * tow1).ToString();
                    }
                    else if (caozuo == '-')
                    {
                        this.richTextBox1.Text += "
    ";
                        this.richTextBox1.Text += (one1 - tow1).ToString();
                    }
                    else if (caozuo == '÷')
                    {
                        this.richTextBox1.Text += "
    ";
                        this.richTextBox1.Text += (one1 / tow1).ToString();
                    }
                    else if (caozuo == '%')
                    {
                        if (one.Contains(".") == true || tow.Contains("."))
                            MessageBox.Show("操作错误,不可有小数");
                        else
                        {
                            this.richTextBox1.Text += "
    ";
                            this.richTextBox1.Text += (one1 % tow1).ToString();
                        }
    
                    }
                }
                    
            }
    
            private void button12_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += ".";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += ".";
            }
    
            private void button10_Click(object sender, EventArgs e)
            {
                if (biaoji == 0)
                {
                    this.richTextBox1.Text = "";
                    this.richTextBox1.Text += "0";
                    biaoji = 1;
                }
                else
                    this.richTextBox1.Text += "0";
            }
    
            private void button17_Click(object sender, EventArgs e)//<---
            {
                
                if (this.richTextBox1.Text.Length== 0){
                    MessageBox.Show("不可以删除");
                }else
                {
                    int a;
                    a = this.richTextBox1.Text.Length;
                    this.richTextBox1.Text = this.richTextBox1.Text.Substring(0,a-1);
                }
                
            }
    
            private void button18_Click(object sender, EventArgs e)//%
            {
                this.richTextBox1.Text = "";
            }
    
            private void 简单计算器_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == '1')
                {
                    button8_Click(null, null);
                }
                if (e.KeyChar == '2')
                {
                    MessageBox.Show(e.KeyChar.ToString());
                    button9_Click(null, null);
                }
                if (e.KeyChar == '3')
                {
                    button7_Click(null, null);
                }
                if (e.KeyChar == '4')
                {
                    button4_Click(null, null);
                }
                if (e.KeyChar == '5')
                {
                    button5_Click(null, null);
                }
                if (e.KeyChar == '6')
                {
                    button6_Click(null, null);
                }
                if (e.KeyChar == '7')
                {
                    button3_Click(null, null);
                }
                if (e.KeyChar == '8')
                {
                    button2_Click(null, null);
                }
                if (e.KeyChar == '9')
                {
                    button1_Click(null, null);
                }
                if (e.KeyChar == '0')
                {
                    button10_Click(null, null);
                }
                if (e.KeyChar == '+')
                {
                    button16_Click(null, null);
                }
                if (e.KeyChar == '-')
                {
                    button13_Click(null, null);
                }
                if (e.KeyChar == '*')
                {
                    button15_Click(null, null);
                }
                if (e.KeyChar == '/')
                {
                    button14_Click(null, null);
                }
                if (e.KeyChar == '=')
                {
                    button11_Click(null, null);
                }
            }
        }
    }
    

    菜鸡一枚,代码需要改善,可以采用

    打包文件地址:链接:https://pan.baidu.com/s/1kQUXHVKrHwbR2uZh-f0Xvg 
    提取码:0u6y 
    复制这段内容后打开百度网盘手机App,操作更方便哦

  • 相关阅读:
    EF基于方法的查询语法
    &,^,|,的简化计算与理解
    会计中阿拉伯数字变数字繁体大写
    接口对接请求方法
    经验总结之Android framework开发
    android开机过程简单描述
    为什么一个类的全局变量默认以m开头?
    使用DataOutputStream写入int类型数字不能显示
    20151128学习总结
    sky简介
  • 原文地址:https://www.cnblogs.com/gaochunhui/p/11053913.html
Copyright © 2020-2023  润新知