private bool Check_LastSymb(object sender) { char ch = char.Parse((sender as Button).Tag.ToString()); if (RPN.IsOperand(ch) || RPN.IsSpecSymb(ch) || Char.IsDigit(ch)) { if (textbox.Text != "") { char[] txt = textbox.Text.ToCharArray(); if (!RPN.IsOperand(txt[txt.Length - 1])) { return(true); } if (RPN.IsSpecSymb(ch) || Char.IsDigit(ch)) { return(true); } } else { if (Char.IsDigit(ch)) { return(true); } } } return(false); }
private void Check_LastSymb(object sender, KeyPressEventArgs e) { char number = e.KeyChar; e.Handled = true; if (RPN.IsOperand(number) || RPN.IsSpecSymb(number) || Char.IsDigit(number) || number == 8) { if (textbox.Text != "") { char[] txt = textbox.Text.ToCharArray(); if (!RPN.IsOperand(txt[txt.Length - 1])) { e.Handled = false; } if (RPN.IsSpecSymb(number) || Char.IsDigit(number)) { e.Handled = false; } if (number == 8) { e.Handled = false; } } else { if (Char.IsDigit(number)) { e.Handled = false; } } } }
private void pm_switch(object sender, EventArgs e) { if (!CheckLock()) { if (textbox.Text != "") { bool check = true; string newText = ""; char[] src = textbox.Text.ToCharArray(); int pos = src.Length - 1; int i = -1; for (; pos >= 0; pos--) { if (check) { if (!Char.IsDigit(src[pos])) { check = false; i = pos; break; } if (pos == 0) { check = false; i = -1; } } } for (int j = 0; j < src.Length; j++) { if (j == 0 && i == -1) { newText += "-" + src[0]; } else { if (j == i) { switch (src[j]) { case '+': { newText += "-"; } break; case '-': { if (j != 0 && !RPN.IsOperand(src[j - 1])) { newText += "+"; } } break; default: { newText += src[j] + "-"; } break; } } else { newText += src[j]; } } } textbox.Text = newText; } else { textbox.Text = "-"; } } }