我的代码如下:
先定义变量:
bool isDone=false, is Decimal=false, is Second=false;
double num1=0,num2=0; char Operator='+';
数字键:(0-9)
Button btn=(Button)sender;
if(isDone)
{this.textBox1.Text=btn.text;
isDone=false;isDecimal=false;
}
else if (isSecond)
{this.textBox1.text=btn.text;
isSecond=true;isDecimal=false;
}
else this.textBox1.text+=btn.text;
小数点:
if(!isDecimal)
{this.textBox1.text+=".";
isDecimal=true;
}
符号:
Button btn=(Button)sender;
Operator=btn.text[0];
if(this.textBox1.text.Lenght>0)
{
num1=double.Parse(this.textBox1.text);
isSecond=true;isDecimal=false;
}
等于号:
if(!isDone)
{double result=0;
if(this.textBox1.text.lenght>0)
num2=double.parse(this.textBox1.text);
switch(Operator)
{case '+':.....................;break;
case '-':......................;break;
}
this.textBox1.text=result;
isDone=false;
}