usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace 计算器实验1{publicpartialclassForm1:Form{double first =0;double last =0;double result =0;bool c =false;string d="";publicForm1(){InitializeComponent();}privatevoidForm1_Load(object sender,EventArgs e){
textBox1.Text ="0";}privatevoidbutton2_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="0";}privatevoidbutton3_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +=".";}privatevoidbutton5_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="1";}privatevoidbutton6_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="2";}privatevoidbutton7_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="3";}privatevoidbutton9_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="4";}privatevoidbutton10_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="5";}privatevoidbutton11_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="6";}privatevoidbutton13_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="7";}privatevoidbutton14_Clic(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="8";}privatevoidbutton15_Click(object sender,EventArgs e){if(c ==true){
textBox1.Text ="";
c =false;}
textBox1.Text +="9";}privatevoidbutton20_Click(object sender,EventArgs e)// /{
c =true;
first =double.Parse(textBox1.Text);
d ="/";}privatevoidbutton16_Click(object sender,EventArgs e)//*{
c =true;
first =double.Parse(textBox1.Text);
d ="*";}privatevoidbutton12_Click(object sender,EventArgs e)//-{if(textBox1.Text =="0")
textBox1.Text ="-";else{
c =true;
first =double.Parse(textBox1.Text);
d ="-";}}privatevoidbutton8_Click(object sender,EventArgs e)//+{
c =true;
first =double.Parse(textBox1.Text);
d ="+";}privatevoidbutton1_Click(object sender,EventArgs e)//取反{if(double.Parse(textBox1.Text)>0)
textBox1.Text ="-"+ textBox1.Text;elseif(double.Parse(textBox1.Text)<0)
textBox1.Text =-double.Parse(textBox1.Text)+"";}privatevoidbutton17_Click(object sender,EventArgs e)//C{
textBox1.Text ="";
first =0;
last =0;
result =0;
d ="";
c =false;}privatevoidbutton4_Click(object sender,EventArgs e)//={switch(d){case"+":result = first +double.Parse(textBox1.Text);break;case"-": result = first -double.Parse(textBox1.Text);break;case"*": result = first *double.Parse(textBox1.Text);break;case"/": result = first /double.Parse(textBox1.Text);break;case"x²":if(first !=0) result = first * first;elseif(double.Parse(textBox1.Text)!=0) result = last * last;break;case"√X":if(first !=0) result = Math.Sqrt(first);elseif(double.Parse(textBox1.Text)!=0) result = Math.Sqrt(last);break;}
textBox1.Text = result+"";}privatevoidbutton18_Click(object sender,EventArgs e)//平方{
c =true;
first =double.Parse(textBox1.Text);
d ="x²";}privatevoidbutton19_Click(object sender,EventArgs e)//开根号{
c =true;
first =double.Parse(textBox1.Text);
d ="√X";}}}