首先我们要自己搭好页面
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 _7_简易计算器
{public partial class Form1 : Form{//定义public static double a = 0;public static string b = "";public static string c="";public static string d = "";public static string result;public Form1(){InitializeComponent();}private void button0_Click(object sender, EventArgs e){Button firstnumber=(Button)sender; //把他们的按钮合并成一个事件 像 0-9和一个小数点b+= firstnumber.Text; //接收第一个数d+= firstnumber.Text; //同样接收textBox1.Text = d; //把d 也就是接收的第一个数赋值给那个 textbox.text//textBox1.Text = b;}private void buttonAdd_Click(object sender, EventArgs e){Button Fuhao=(Button)sender; //把他们的符号绑定成一个事件 +-*/这四个if (c != "") //首先这一步不会进行 他目前`是空 运算完之后,如果用户还想拿结果进行运算,就可以带入{switch (c){case "+":a += double.Parse(b);break;case "-":a -= double.Parse(b);break;case "*":a /= double.Parse(b);break;case "/":if (double.Parse(b) == 0){MessageBox.Show("简易计算机", "根据数学界,除数不能为0", MessageBoxButtons.OK);a = 0;b = "";textBox1.Text = "";return;}a /= double.Parse(b);break;}} else{a += double.Parse(b);//接收b 并且把b赋值给a}b = ""; //赋值之后b现在为空了c=Fuhao.Text; //符号赋值给cd += c; //这根就是第一个数与符号的了 比如5+ d是5 c是符号+textBox1.Text=d; //现在把d赋值到文本上显示}private void buttonEquals_Click(object sender, EventArgs e){switch (c){case "+":a += double.Parse(b);break;case "-":a -= double.Parse(b);break;case "*":a *= double.Parse(b);break;case "/":if (double.Parse(b) == 0){MessageBox.Show("简易计算机", "根据数学界,除数不能为0", MessageBoxButtons.OK);a = 0;b = "";textBox1.Text = "";return;}a /= double.Parse(b);break;}d=a.ToString(); //把a赋值给d 上面a是已经运算出来的值了;textBox1.Text=d; //将d 结果赋值给屏幕文本b = a.ToString(); c = "";}private void buttonClear_Click(object sender, EventArgs e){a= 0;b = "";c = "";d = "";textBox1.Text = "";}}
}