设计一个简单的计算器,实现两个数的加、减、乘、除、求幂运算。
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 _2_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)//加
{
double a = Convert.ToDouble(txtA.Text);
double b = Convert.ToDouble(txtB.Text);
lblShow.Text = a + "+" + b + "=";
lblShow.Text += (a + b).ToString();
}
private void button2_Click(object sender, EventArgs e)//减
{
double a = Convert.ToDouble(txtA.Text);
double b = Convert.ToDouble(txtB.Text);
lblShow.Text = a + "-" + b + "=";
lblShow.Text += (a - b).ToString();
}
private void button3_Click(object sender, EventArgs e)//乘
{
double a = Convert.ToDouble(txtA.Text);
double b = Convert.ToDouble(txtB.Text);
lblShow.Text = a + "*" + b + "=";
lblShow.Text += (a * b).ToString();
}
private void button4_Click(object sender, EventArgs e)//除
{
double a = Convert.ToDouble(txtA.Text);
double b = Convert.ToDouble(txtB.Text);
lblShow.Text = a + "/" + b + "=";
lblShow.Text += (a / b).ToString();
}
private void button5_Click(object sender, EventArgs e)//幂运算
{
double a = Convert.ToDouble(txtA.Text);
double b = Convert.ToDouble(txtB.Text);
lblShow.Text = a + "的" + b + "次方等于";
lblShow.Text += Math.Pow(a,b);
}
}
}