如何用C#写一个普通的计算器.欢迎大家发表意见,回答满意者给100分,我是新手,望大家写的尽量详细,,
解决方案 »
- 关闭浏览器session变为空的问题
- 谁来给我解释解释,为什么WPF的grid没有双击事件?
- C# 使用SqlDataReader取一条记录的一个字段的字符串.
- 本人最近写的很乱 C++ c# vb asp php都用了有点感悟
- 使用BackgroundWorker绑定DataGridView 提示正在加载
- 如何删除xml节点信息
- 客户端使用Webclient.UploadFile发送文件给一个网页,在网页侧怎么接收
- 怎样用WIS打包时讲。NET框架装进去?
- C# Timer控件
- 判断是否是数字
- .NET Remoting 双向通信问题
- microsoftReportViewer 为何在“打印布局”里多处很多张空白页?
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication18
{
class Program
{
public class calc
{
private System.Data.DataTable dt = new System.Data.DataTable();
public string Compute(string str)
{
return dt.Compute(str, "").ToString();
}
}
static void Main(string[] args)
{
calc c= new calc();
Console.WriteLine(c.Compute("1+1"));
Console.WriteLine(c.Compute("1*3"));
Console.WriteLine(c.Compute("(1+3)*2/5"));
Console.ReadKey();
}
}
}
可以仿照windows自带的计算器界面
科学计算器实现起来估计会更困难,一般的计算方法参考math下的方法就ok
蛮复杂的。
用工厂方法。来做。
C#的一般开发模式介绍的相当详细。
class operation
{
math(x,y)
}
class operationadd:operation
{
math(x,y)
{
x+y
]}
class operationdel:operation
{
x-y
}
factoryoperation,工厂类。{
operation getoperation(string o)
{
swith o
case "+"
return new operationadd
break}
}
Windows程序比较费劲。。
http://search.download.csdn.net/search/C%23%20%E8%AE%A1%E7%AE%97%E5%99%A8http://download.csdn.net/source/179632楼主自己选几个下来看看吧。
http://bbs.chinaitlab.com/frame.php?frameon=yes&referer=http%3A//bbs.chinaitlab.com/thread-249039-1-2.html
写这个算是比较容易的。但不出BUGGER是比较难的
double first, second;
string input;
bool sfcz = false;
delegate double ProcessDelegate(double param1,double param2); private double add(double param1, double param2)
{
return param1 + param2;
} private double del(double param1, double param2)
{
return param1 - param2;
} private double Multiply(double param1, double param2)
{
return param1 * param2;
} private double Divide(double param1, double param2)
{
return param1 / param2;
} //数字1按钮事件 其他数字类似 不多写了
private void button1_Click(object sender, EventArgs e)
{
if (sfcz)
{
sfcz = false;
textBox1.Text = "";
}
textBox1.Text += "1";
} //加号按钮事件 其他减乘除类似 不多写了
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() != "")
{
sfcz = true;
}
first = Convert.ToDouble(textBox1.Text);
input = "加";
}//等号按钮事件
private void button15_Click(object sender, EventArgs e)
{
second = Convert.ToDouble(textBox1.Text);
ProcessDelegate process;
if (input == "加")
{
process = new ProcessDelegate(add);
}
else if (input == "减")
{
process = new ProcessDelegate(del);
}
else if (input == "乘")
{
process = new ProcessDelegate(Multiply);
}
else if (input == "除")
{
process = new ProcessDelegate(Divide);
}
else
{
//textBox1.Text = "请选择操作符";
MessageBox.Show("请选择操作符");
return;
}
textBox1.Text = process(first, second).ToString();
}简单的实现了下 ,我想思路应该就这样 很多细节都没处理 要想做一个好的计算器软件出来还要有很多工作要做
http://download.csdn.net/source/291518
http://tech.ddvip.com/2006-08/11544026776577.html
硅谷动力下载链接:
http://download.enet.com.cn/html/033432007101201.html
华军软件园:
http://www.newhua.com/soft/61874.htm
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 简易计算器
{
public partial class Form1 : Form
{
double num1 = 0, num2 = 0, result = 0;
int type = 0;
int dot_num = 1;
bool is_num1 = false;
bool is_dot = false;
bool is_fushu = false;
bool doted = false; void func(int numb)
{
if (is_num1 == false)
{
if (is_dot == true)
{
double tempNum = 1;
for (int i = 0; i < dot_num; i++)
{
tempNum = 10 * tempNum;
}
if (!is_fushu)
num1 = num1 + (double)numb / (double)(tempNum);
else
num1 = num1 - (double)numb / (double)(tempNum);
dot_num++;
}
else
{
if (!is_fushu)
num1 = num1 * 10 + numb;
else
num1 = num1 * 10 - numb;
}
textBox1.Text = num1.ToString();
}
else
{
if (is_dot == true)
{
double tempNum = 1;
for (int i = 0; i < dot_num; i++)
{
tempNum = 10 * tempNum;
}
if (!is_fushu)
num2 = num2 + (double)numb / (double)(tempNum);
else
num2 = num2 - (double)numb / (double)(tempNum);
dot_num++;
}
else
{
if (!is_fushu)
num2 = num2 * 10 + numb;
else
num2 = num2 * 10 - numb;
}
textBox1.Text = num2.ToString();
}
} void calType()
{
is_num1 = true;
dot_num = 1;
is_dot = false;
is_fushu = false;
doted = false;
}
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
func(1);
} private void button2_Click(object sender, EventArgs e)
{
func(2);
} private void button3_Click(object sender, EventArgs e)
{
func(3);
} private void button4_Click(object sender, EventArgs e)
{
func(4);
} private void button5_Click(object sender, EventArgs e)
{
func(5);
} private void button6_Click(object sender, EventArgs e)
{
func(6);
} private void button7_Click(object sender, EventArgs e)
{
func(7);
} private void button8_Click(object sender, EventArgs e)
{
func(8);
} private void button9_Click(object sender, EventArgs e)
{
func(9);
} private void button10_Click(object sender, EventArgs e)
{
func(0);
} private void button11_Click(object sender, EventArgs e)
{
is_dot = true;
if (doted == false)
{
doted = true;
dot_num = 1;
}
} private void button13_Click(object sender, EventArgs e)
{
type = 1;
calType();
textBox1.Text = "+";
} private void button14_Click(object sender, EventArgs e)
{
type = 2;
textBox1.Text = "-";
calType();
} private void button15_Click(object sender, EventArgs e)
{
type = 3;
textBox1.Text = "*";
calType();
} private void button16_Click(object sender, EventArgs e)
{
type = 4;
textBox1.Text = "/";
calType();
} private void button12_Click(object sender, EventArgs e)
{
switch (type)
{
case 1: result = num1 + num2;
break;
case 2: result = num1 - num2;
break;
case 3: result = num1 * num2;
break;
case 4: result = num1 / num2;
break;
}
textBox1.Text = textBox1.Text + "=" + result.ToString();
num1 = 0;
num2 = 0;
is_num1 = false;
dot_num = 1;
is_dot = false;
is_fushu = false;
doted = false;
} private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = "";
num1 = 0;
num2 = 0;
result = 0;
type = 0;
dot_num = 1;
is_num1 = false;
is_dot = false;
is_fushu = false;
doted = false;
}
}
}
http://www.wfsoft.com/software_info.asp?id=30090
http://www.wfsoft.com/software_info.asp?id=30010
不过是winform
而且调试了半天我都懒得看了
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;namespace WindowsApplication1
{
public partial class expression : Form
{
public expression()
{
InitializeComponent();
} /**
* 单击“计算结果”按钮时触发的事件方法
*/
private void getResult(object sender, EventArgs e)
{
string expStr = expTxt.Text;//获取输入框--表达式的内容
if (!Analisys(expStr))
message.Text = "输入的表达式不合法!";
else
{
message.Text = "";
resultTxt.Text = parseAndResult(expStr);
}
} /**
* 单击“取消”按钮,关闭窗口
*/
private void cancal(object sender, EventArgs e)
{
this.Close();
} /**
* 判断录入的字符串是不是一个合法的数学表达式
*/
private bool Analisys(string expStr)
{
int dep = 0; //表达式嵌套括号的层数
int temp = 0;
for (int i = 0; i < expStr.Length; i++)
{
if (expStr[i] == '(')
temp++;
else if (expStr[i] == ')')
temp--;
if (temp > dep)
dep = temp;
}
string signUnit = @"(\+|\-|\*|\/)";
string unitRegex = @"(\-)?(([0-9]+)|([0-9]+\.[0-9]+))(" + signUnit
+ @"(((([0-9]+)|([0-9]+\.[0-9]+)))|(\(\-(([0-9]+)|([0-9]+\.[0-9]+))\))))*";
string braUnit = @"(\(" + unitRegex + @"\))";
string halfEndRegex = "((" + unitRegex + ")|(" + braUnit + "(" + signUnit + "(" + braUnit + "|" + unitRegex + "))+))";
string endRegex = halfEndRegex +"("+ signUnit +"("+halfEndRegex +"|"+braUnit + "))*";
for (int i = 1; i < dep; i++)
{
string tempRule = @"(\(" + endRegex + @"\))";
string rule = "((" + endRegex + ")|(" + tempRule + "(" + signUnit + "(" + endRegex + "|" + tempRule + "))+))";
endRegex = rule + "(" + signUnit + "(" + rule + "|" + tempRule + "))*";
}
string endRule = "^" + endRegex+"$";
Regex regex = new Regex(endRule);
Match match = regex.Match(expStr);
if(match.Success)
return true;
return false;
} /**
* 解析并计算数学表达式的结果
*/
private string parseAndResult(string exp)
{//递归方法,用计算结果替换表达式被计算过的部分,再调用该方法!
if (exp.IndexOf('(') == -1)
return calculate(exp);
int n = exp.IndexOf('(') + 1;
int i = exp.IndexOf('(') + 1;
for (; i < exp.Length; i++)
{
if (exp[i] == '(')
n = i + 1;
else if (exp[i] == ')')
break;
}
string tempResult = calculate(exp.Substring(n, i - n));
return parseAndResult(exp.Substring(0, n - 1) + tempResult + exp.Substring(i + 1));
} /**
* 计算不含有括号的数学表达式的结果
*/
private string calculate(string exp)
{
int n = 0; //运算符的位置
String tempA = ""; //运算符前面的数
String tempB = ""; //运算符后面的数
if ((n = exp.IndexOf('/')) != -1 || (n = exp.IndexOf('*')) != -1)
{//当表达式中含有'/'先进行除运算,如果表达式中含有'*'运算则进行乘运算
int i = n - 1;
for (; i >= 0; i--)
{
if (!Char.IsDigit(exp[i]) && i != 0 && exp[i] != '.')
break;
}
tempA = exp.Substring(i + 1, n - i - 1);
int j = n + 1;
for (; j < exp.Length; j++)
{
if (j == n + 1 && exp[j] == '-')
continue;
if (!Char.IsDigit(exp[j]) && exp[j] != '.')
break;
}
tempB = exp.Substring(n + 1, j - n - 1);
if (exp[n] == '*')
return calculate(exp.Substring(0, i + 1) + (double.Parse(tempA) * double.Parse(tempB)) + exp.Substring(j));
else
return calculate(exp.Substring(0, i + 1) + (double.Parse(tempA) / double.Parse(tempB)) + exp.Substring(j));
}
else if ((n = exp.IndexOf('+')) != -1 || (n = exp.IndexOf('-')) != -1)
{//如果表达式中不含有'*'和'/'但含有'-'(并且不是第一个字符,是第一个字符时则把它看做是单项运算符)和'+'完成减、加运算
for (int i = 1; i < exp.Length; i++)
{
if (!Char.IsDigit(exp[i]) && exp[i] != '.')
{
n = i;
break;
}
}
tempA = exp.Substring(0, n);
int j = n + 1;
for (; j < exp.Length; j++)
{
if (j == n + 1 && exp[j] == '-')
continue;
if (!Char.IsDigit(exp[j]) && exp[j] != '.')
break;
}
tempB = exp.Substring(n + 1, j - n - 1);
if (exp[n] == '+')
return calculate("" + (double.Parse(tempA) + double.Parse(tempB)) + exp.Substring(j));
else if (n != 0)
return calculate("" + (double.Parse(tempA) - double.Parse(tempB)) + exp.Substring(j));
}
return exp;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private int opMain = 0; // 运算类型,其中1(加法) 2(减法) 3(乘法) 4(除法)
private double mainNum1 = 0; // 存储第一个数
private double mainNum2 = 0; // 存储第二个数
private bool isSecond = false; // 用来判断输入的是第一个还是第二个数
private bool isDone = false; // 用来判断是否按了等于按钮
private bool isDecimal = false; // 用来判断是否有小数
private bool isNokeydown = false;// 用来判断是否没输入第二个数而按了"="号键
private bool isKeyupclear = true ;//用来判断是否按了clear键,程序开始前默认按了;
public void setText(string textest) //设置文本框的值
{
if (textest .Equals ("clear"))
{
textBox1.Text ="0.";
isSecond =false ;
isDone =false ;
isDecimal =false ;
isKeyupclear = true;
}
else
{
if (isSecond )
{
textBox1 .Text =textest ;
isSecond =false ;
isDecimal =false ;
}
else
{
if (isDone )
{
textBox1 .Text =textest ;
isDone =false ;
}
else
{
if (isKeyupclear) //对是否按下clear键的判断
{
textBox1.Text = textest;
isKeyupclear = false;
}
else
textBox1 .Text +=textest ;
}
}
}
button12 .Select (); //设置"="号的焦点
}
public void Calc(double num1, double num2, int op)
{
double answer = 0;
switch (op) //判断所进行的运算
{
case 1:
answer = num1 + num2;
break;
case 2:
answer = num1 - num2;
break;
case 3:
answer = num1 * num2;
break;
case 4:
answer = num1 / num2;
break;
}
setText(answer.ToString()); //显示结果
} //执行运算
private void doEquals()
{
if (isNokeydown ) //判断已经输入第二个数后按了"="号键
{
mainNum2 = double.Parse(textBox1.Text);
setText("clear");
Calc(mainNum1, mainNum2, opMain);
isDone = true;
isNokeydown = false;
}
} //切换正负
private void changeSign()
{
double storNum;
if (textBox1 .Text .Length > 0)
{
storNum = double.Parse(textBox1 .Text );
storNum *= -1;
textBox1 .Text = storNum.ToString();
}
button12.Select(); //设置"="号的焦点
} //设置运算类型
private void setOperator(int operation)
{
if (textBox1 .Text .Length > 0)
{
opMain = operation;
mainNum1 = double.Parse(textBox1 .Text );
isSecond = true;
isDone = false;
isNokeydown = true;
button12.Select(); //设置"="号的焦点
}
} //设置小数点
private void setDecimal()
{
if (!isDecimal)
{
setText(".");
isDecimal = true;
}
button12.Select(); //设置"="号的焦点
} private void button10_Click(object sender, EventArgs e)
{
setText("0");
} private void button11_Click(object sender, EventArgs e) //小数点
{
setDecimal();
} private void button1_Click(object sender, EventArgs e)
{
setText("1");
} private void button2_Click(object sender, EventArgs e)
{
setText("2");
} private void button3_Click(object sender, EventArgs e)
{
setText("3");
} private void button4_Click(object sender, EventArgs e)
{
setText("4");
} private void button5_Click(object sender, EventArgs e)
{
setText("5");
} private void button6_Click(object sender, EventArgs e)
{
setText("6");
} private void button7_Click(object sender, EventArgs e)
{
setText("7");
} private void button8_Click(object sender, EventArgs e)
{
setText("8");
} private void button9_Click(object sender, EventArgs e)
{
setText("9");
} private void button12_Click(object sender, EventArgs e) //"="号键
{
doEquals();
} private void button13_Click(object sender, EventArgs e) //"+"号键
{
setOperator(1);
} private void button14_Click(object sender, EventArgs e) //"-"号键
{
setOperator(2);
} private void button15_Click(object sender, EventArgs e) //"*"号键
{
setOperator(3);
} private void button16_Click(object sender, EventArgs e) //"/"号键
{
setOperator(4);
} private void button17_Click(object sender, EventArgs e) //"c"清除键
{
isSecond = false;
setText("clear");
} private void button18_Click(object sender, EventArgs e)
{
changeSign();
} }
}
http://www.qqread.com/csharp/d902137000.html
希望对你帮助或启发作用!
里面有源码,自己看。
里面有源码,自己看。功能和Windows的基本功能差不多,但没科学计算器那么夸张哈。只是N年前练手的东西
http://www.knowsky.com/300795.html,看看满意不
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;
using System.Runtime.InteropServices;namespace Calculator
{
public partial class FormCalculator : Form
{
#region 成员变量定义 private bool b_decimalSign; //小数标识
private bool b_negativeSign; //负数标识
private char c_operatorSign; //当前被按操作符
private char c_oldOperatorSign; //上一个被按的操作符
private bool b_operatorClick; //操作符是否被按下
private double d_result; //保存计算结果
private double d_middle; //保存一些中间数据
private bool b_exception; //异常标识
private bool b_singleOperatorClick; //单操作符(如sqrt,1/x)是否被按下
private bool b_equalSigh; //"="符号是否被按下
private double d_temp; //保存一些临时数据
private double d_mStore; //M*记忆功能储存 #endregion #region 构造函数 public FormCalculator()
{
InitializeComponent();
ClearAll(); //调用方法初始化变量
} #endregion #region 变量值清空方法,用于按钮调用 private void ClearAll()
{
Clear();
c_oldOperatorSign = '+';
c_operatorSign = '+';
d_result = 0;
b_exception = false;
b_operatorClick = false;
b_singleOperatorClick = false;
b_equalSigh = false;
d_middle = 0;
d_temp = 0;
} private void Clear()
{
b_decimalSign = false;
b_negativeSign = false;
textBoxOut.Text = "0.";
} #endregion #region 异常提醒 [DllImport("user32.dll")]
extern static bool MessageBeep(int a, int b); //插入MessageBeep方法用来异常提醒 //异常提醒方法
private bool CheckException()
{
if (b_exception == true)
{
MessageBeep(100, 100);
return true;
}
else
{
return false;
}
} #endregion #region 通过按钮输入数字的方法 private void InputNumber(string number)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
Clear();
b_operatorClick = false;
}
if (b_singleOperatorClick == true)
{
Clear();
b_singleOperatorClick = false;
}
if (b_decimalSign == true)
{
textBoxOut.Text += number;
}
else
{
if (textBoxOut.Text[0] == '0' || (textBoxOut.Text[0] == '-' && textBoxOut.Text[1] == '0'))
{
if (textBoxOut.Text[0] == '0')
{
textBoxOut.Text = textBoxOut.Text.Remove(0, 1);
}
else
{
textBoxOut.Text = textBoxOut.Text.Remove(1, 1);
}
}
textBoxOut.Text=textBoxOut.Text.Insert(textBoxOut.Text.IndexOf('.'), number);
}
} #endregion
{
if (b_equalSigh != true)
{
d_middle = Double.Parse(textBoxOut.Text);
d_temp = d_middle;
}
else
{
d_middle = d_temp;
b_equalSigh = false;
}
try
{
switch (c_oldOperatorSign)
{
case '+':
d_result += d_middle;
if (d_result.ToString() == "正无穷大" || d_result.ToString() == "负无穷大")
{
b_exception = true;
textBoxOut.Text = "运算结果溢出。";
}
if (d_result.ToString().Contains('.'))
{
textBoxOut.Text = d_result.ToString();
}
else
{
textBoxOut.Text = d_result.ToString() + ".";
}
break;
case '-':
d_result -= d_middle;
if (d_result.ToString() == "正无穷大" || d_result.ToString() == "负无穷大")
{
b_exception = true;
textBoxOut.Text = "运算结果溢出。";
}
if (d_result.ToString().Contains('.'))
{
textBoxOut.Text = d_result.ToString();
}
else
{
textBoxOut.Text = d_result.ToString() + ".";
}
break;
case '*':
d_result *= d_middle;
if (d_result.ToString() == "正无穷大" || d_result.ToString() == "负无穷大")
{
b_exception = true;
textBoxOut.Text = "运算结果溢出。";
}
else if (d_result.ToString().Contains('.'))
{
textBoxOut.Text = d_result.ToString();
}
else
{
textBoxOut.Text = d_result.ToString() + ".";
}
break;
case '/':
d_result /= d_middle;
if (d_result.ToString() == "正无穷大" || d_result.ToString() == "负无穷大")
{
if (d_middle == 0)
{
b_exception = true;
textBoxOut.Text = "除数不能为零。";
}
else
{
b_exception = true;
textBoxOut.Text = "运算结果溢出。";
}
}
else if (d_result.ToString() == "非数字")
{
b_exception = true;
textBoxOut.Text = "函数结果未定义。";
}
else if (d_result.ToString().Contains('.'))
{
textBoxOut.Text = d_result.ToString();
}
else
{
textBoxOut.Text = d_result.ToString() + ".";
}
break;
case '%':
d_result %= d_middle;
if (d_result.ToString() == "非数字")
{
b_exception = true;
textBoxOut.Text = "函数输入无效。";
}
else if (d_result.ToString().Contains('.'))
{
textBoxOut.Text = d_result.ToString();
}
else
{
textBoxOut.Text = d_result.ToString() + ".";
}
break;
case 'S':
d_middle = Math.Sqrt(d_middle);
if (d_middle.ToString() == "非数字")
{
b_exception = true;
textBoxOut.Text = "函数输入无效。";
}
else if (d_middle.ToString().Contains('.'))
{
textBoxOut.Text = d_middle.ToString();
}
else
{
textBoxOut.Text = d_middle.ToString() + ".";
}
c_oldOperatorSign = c_operatorSign;
break;
case 'R':
d_middle = 1.0 / d_middle;
if (d_middle.ToString() == "正无穷大" || d_middle.ToString() == "负无穷大")
{
b_exception = true;
textBoxOut.Text = "除数不能为零。";
}
else if (d_middle.ToString().Contains('.'))
{
textBoxOut.Text = d_middle.ToString();
}
else
{
textBoxOut.Text = d_middle.ToString() + ".";
}
c_oldOperatorSign = c_operatorSign;
break;
}
}
catch
{
b_exception = true;
} } #endregion
{
InputNumber("0");
} private void button1_Click(object sender, EventArgs e)
{
InputNumber("1");
}
private void button2_Click(object sender, EventArgs e)
{
InputNumber("2");
} private void button3_Click(object sender, EventArgs e)
{
InputNumber("3");
} private void button4_Click(object sender, EventArgs e)
{
InputNumber("4");
} private void button5_Click(object sender, EventArgs e)
{
InputNumber("5");
} private void button6_Click(object sender, EventArgs e)
{
InputNumber("6");
} private void button7_Click(object sender, EventArgs e)
{
InputNumber("7");
} private void button8_Click(object sender, EventArgs e)
{
InputNumber("8");
} private void button9_Click(object sender, EventArgs e)
{
InputNumber("9");
} #endregion #region 小数点、正负号按钮方法 private void buttonPoint_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
Clear();
b_operatorClick = false;
}
b_decimalSign = true;
} private void buttonSign_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
Clear();
b_operatorClick = false;
}
if (b_negativeSign == true)
{
b_negativeSign = false;
textBoxOut.Text = textBoxOut.Text.Trim('-');
}
else
{
b_negativeSign = true;
textBoxOut.Text = '-' + textBoxOut.Text;
} } #endregion #region +、-、*、/按钮方法 private void buttonAdd_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '+';
}
else
{
b_operatorClick = true;
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '+';
Calculate();
}
} private void buttonSub_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '-';
}
else
{
b_operatorClick = true;
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '-';
Calculate();
}
} private void buttonMul_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '*';
}
else
{
b_operatorClick = true;
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '*';
Calculate();
}
} private void buttonDiv_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '/';
}
else
{
b_operatorClick = true;
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '/';
Calculate();
}
} #endregion #region 清除、清除全部按钮方法 private void buttonClear_Click(object sender, EventArgs e)
{
if (b_exception==true)
{
ClearAll();
}
else
{
Clear();
} } private void buttonClearAll_Click(object sender, EventArgs e)
{
ClearAll();
} #endregion #region =、%(求余)、求倒数、开平方方法 private void buttonEqual_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (c_operatorSign != '=')
{
c_oldOperatorSign = c_operatorSign;
}
else
{
b_equalSigh = true;
}
b_operatorClick = true;
c_operatorSign = '=';
Calculate();
} private void buttonResidue_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
if (b_operatorClick == true)
{
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '%';
}
else
{
b_operatorClick = true;
c_oldOperatorSign = c_operatorSign;
c_operatorSign = '%';
Calculate();
}
} private void buttonReciprocal_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
b_operatorClick = false;
b_singleOperatorClick = true;
c_oldOperatorSign = 'R';
Calculate();
} private void buttonSqrt_Click(object sender, EventArgs e)
{
if (CheckException())
{
return;
}
b_operatorClick = false;
b_singleOperatorClick = true;
c_oldOperatorSign = 'S';
Calculate();
} #endregion