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;

 

namespace aa

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button5_Click(object sender, EventArgs e)

        {

            double  x = Convert.ToDouble(textBox1 .Text );

            double  y = Convert.ToDouble (textBox2 .Text );

            double  result=Math.Pow (x,y);

            label3.Text = textBox1 .Text +"的"+textBox2 .Text +"次方为"+result ;

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x+y;

            label3.Text = textBox1.Text + "+" + textBox2.Text + "的值为" + result;

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x - y;

            label3.Text = textBox1.Text + "-" + textBox2.Text + "的值为" + result;

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x * y;

            label3.Text = textBox1.Text + "*" + textBox2.Text + "的值为" + result;

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

            double x = Convert.ToDouble(textBox1.Text);

            double y = Convert.ToDouble(textBox2.Text);

            double result = x /y;

            label3.Text = textBox1.Text + "/" + textBox2.Text + "的值为" + result;

        }

 

    }

}

 

运行结果:

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值