美文网首页
使用c#.net实现winform简单计算器

使用c#.net实现winform简单计算器

作者: 前端毛毛 | 来源:发表于2018-11-30 14:34 被阅读0次

    使用c#.net实现简单计算器 本程序使用visual studio 2010实现
    效果图如下

    计算器.gif

    需求分析:
    实现计算器简单加减乘除 删除 以及 clear功能

    实现原理:实现button的click事件

    获取计算器1~9的button中的text

     private void button1_Click(object sender, EventArgs e)
            {
                Button a=(Button)sender;
                this.textBox1.Text += a.Text;
                
            }
    

    获取和存储运算符

     private void buttonjia_Click(object sender, EventArgs e)
            {
                num1 = int.Parse(this.textBox1.Text);
                
                this.textBox1.Text = "";
                Button b = (Button)sender;
                f = b.Text;
            }
    

    实现加减乘除

    private void buttonresult_Click(object sender, EventArgs e)
            {
                num2 = int.Parse(this.textBox1.Text);
                if(f=="+")
                {
                    this.textBox1.Text=(num1+num2).ToString();
                }
                if (f == "-")
                {
                    this.textBox1.Text = (num1 - num2).ToString();
                }
                if (f == "*")
                {
                    this.textBox1.Text = (num1 * num2).ToString();
                }
                if (f == "/")
                {
                    this.textBox1.Text = (num1 / num2).ToString();
                }
    
            }
    

    清空输入框

    this.textBox1.Clear();
    

    删除

    textBox1.Text = textBox1.Text.Substring(0, textBox1.TextLength - 1);
    

    相关文章

      网友评论

          本文标题:使用c#.net实现winform简单计算器

          本文链接:https://www.haomeiwen.com/subject/iokhcqtx.html