标题:计算器怎么进行二次计算
取消只看楼主
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
结帖率:0
已结贴  问题点数:20 回复次数:3 
计算器怎么进行二次计算
        private string a=null;
        private string b=null;
        private double c=0;
        private string sign=null;
        private bool dian=false;
        

        public Form1()
        {
            InitializeComponent();
        }
        //跟按钮的单击事件关联的方法
        private void button3_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "0";
            }
            else if (a == null)
            {
                a = "0";
            }
            textBox1.Text = a;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "1";
            }
            else if (a == null)
            {
                a = "1";
            }
            textBox1.Text = a;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (dian == false)
            {
                dian = true;
                if (a != null)
                {
                    a = a + ".";
                }
                else
                {
                    a = "0.";
                }
                textBox1.Text = a;
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "+";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if(sign =="+")
            {
                c = Convert.ToDouble(a) + Convert.ToDouble(b);
            }
            if(sign =="-")
            {
                c = Convert.ToDouble(b) - Convert.ToDouble(a);
            }
            if (sign == "*")
            {
                c = Convert.ToDouble(a) * Convert.ToDouble(b);
            }
            if (sign == "/")
            {
                c = Convert.ToDouble(b) / Convert.ToDouble(a);
            }
            textBox1.Text = Convert.ToString(c);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "2";
            }
            else if (a == null)
            {
                a = "2";
            }
            textBox1.Text = a;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "3";
            }
            else if (a == null)
            {
                a = "3";
            }
            textBox1.Text = a;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "4";
            }
            else if (a == null)
            {
                a = "4";
            }
            textBox1.Text = a;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "5";
            }
            else if (a == null)
            {
                a = "5";
            }
            textBox1.Text = a;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "6";
            }
            else if (a == null)
            {
                a = "6";
            }
            textBox1.Text = a;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "7";
            }
            else if (a == null)
            {
                a = "7";
            }
            textBox1.Text = a;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "8";
            }
            else if (a == null)
            {
                a = "8";
            }
            textBox1.Text = a;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (a != null && a != "0")
            {
                a = a + "9";
            }
            else if (a == null)
            {
                a = "9";
            }
            textBox1.Text = a;
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "-";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "*";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (sign == null)
            {
                sign = "/";
                b = a;
                a = null;
                dian = false;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button17_Click(object sender, EventArgs e)
        {
            textBox1.Text = "0";
            c = 0;
            a = null;
            b = null;
            dian = false;
            sign = null;
        }
搜索更多相关主题的帖子: 计算器 private public double false 
2015-12-22 12:54
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
得分:0 
回复 2楼 afdoa83
我还是搞不懂能不能帮我弄一下
新建计算.zip (54.3 KB)
2015-12-22 14:00
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
得分:0 
回复 4楼 wp231957
就是覆盖前面的结果,进行下一次计算
2015-12-22 14:37
即使你在
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-12-8
得分:0 
回复 6楼 wp231957
这个我知道,我的意思是不要用CE这个键,像我们平常计算器可以覆盖,可以叠加
2015-12-22 14:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-460456-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.103457 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved