/// 按下符号时进行计算 private void Flag_mul_Click(object sender, EventArgs e) { numStr.Clear(); ///清空里面的东西 double result = 0; //保存返回的结果 string text = ((Button)sender).Text; switch (text) { case "+": nextFlag = prevFlag; ///保存前一个 prevFlag = FlagEnum.ADD; break; case "-": nextFlag = prevFlag; prevFlag = FlagEnum.SUB; break; case "*": nextFlag = prevFlag; prevFlag = FlagEnum.MUL; break; case "/": nextFlag = prevFlag; prevFlag = FlagEnum.DIV; break; case "Mod": nextFlag = prevFlag; prevFlag = FlagEnum.MOD; break; case "=": nextFlag = prevFlag; prevFlag = FlagEnum.EQ; break; case "CE": //nextFlag = prevFlag; //prevFlag = FlagEnum.CE; caculate.ClearStack(); return; ///end break; } ///进行计算操作 if (flag) { flag = false; return;///第一次遇到符号不操作 } else { result = CaculateCore(nextFlag); } text_show_caclute.Text = "" + result; }
private bool flag; ///第一次遇到符号不计算标识 public Caculate() { InitializeComponent(); numStr = new StringBuilder(); caculate = new Caculate10(); radioButton2.Checked = true;///默许十进制 caculate.ClearStack(); init(); }