| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1331 人关注过本帖
标题:计算器如何进行连续运算和混合运算?
只看楼主 加入收藏
伍嚎
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-4-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
计算器如何进行连续运算和混合运算?
这是我编的代码,只能运算一次就得按等号,求在此基础上实现连续运算和混合运算的方法如:5+6+7+8=?5+9*5=?
  private void button1_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            textBox1.Text = textBox1.Text + btn.Text; //以上两步能在Textbox中输入按钮的数字,用了老师教的方法
            
        }
        string a ;
      
        string f;
        double num1;

        private void button14_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            a = textBox1.Text;
            num1 = Convert.ToDouble(a);
            textBox1.Text = "";
            f = btn.Text;          //以上获取第一个数并清空Textbox,f为运算符的类型(+、-、*、\)
            

            


        }
        
        private void button18_Click(object sender, EventArgs e)//以下为运算过程
        {
            if (f == "+")
            {
                double c = num1 + Convert.ToDouble(textBox1.Text);
               
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "-")
            {
                double c = num1 - Convert.ToDouble(textBox1.Text);
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "*")
            {
                double c = num1 * Convert.ToDouble(textBox1.Text);
                textBox1.Text = Convert.ToString(c);
            }
            else if (f == "/")
            {
                double c = num1 / Convert.ToDouble(textBox1.Text);
                textBox1.Text = Convert.ToString(c);
            }

        }

        private void button17_Click(object sender, EventArgs e)//清空
        {
            textBox1.Text = "";
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text != "" )
            {
                double d = double.Parse(this.textBox1.Text);
                if (d != 0)
                {
                    this.textBox1.Text = (-d).ToString();
                }
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        string t;
        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            t = textBox1.Text;
        }

        private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = t;
        }

        private void 文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 版本信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 newform = new Form2();
            newform.ShowDialog();
        }

        private void button19_Click(object sender, EventArgs e)
        {
            if (1 == textBox1.Text.Length)
            {
                textBox1.Text = "";
            }
            else
            {
                textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
ex4调试版.rar (53.03 KB)


[ 本帖最后由 伍嚎 于 2011-5-7 23:17 编辑 ]
搜索更多相关主题的帖子: 计算器 
2011-05-07 22:45
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:14 
我也只能做到这种程度,要做像WIN7自带的计算器那样就难了!

   唯实惟新 至诚致志
2011-05-07 23:51
快速回复:计算器如何进行连续运算和混合运算?
数据加载中...
 
   



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

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