private void equalClick(object sender, EventArgs e) { if (inputTextBox.Text.Length > 1 && areBracketsClosed()) { if (currentNumber != "") { if (elements.Count == 0) { return; } elements.Add(currentNumber); currentNumber = ""; isNumberLast = false; result = Convert.ToString(ONP.Calculate(elements)); elements.Clear(); if (inputTextBox.Text.Length + result.Length > 22) { inputTextBox.Text = "=" + result; } else { inputTextBox.Text += "=" + result; } } else if (elements.Count > 0 && elements.Last() == ")") { result = Convert.ToString(ONP.Calculate(elements)); elements.Clear(); isNumberLast = false; if (inputTextBox.Text.Length + result.Length > 22) { inputTextBox.Text = "=" + result; } else { inputTextBox.Text += "=" + result; } } } }
private void operatorClick(object sender, EventArgs e) { if (inputTextBox.Text.Length > 22) { return; } string text = ((Button)sender).Text; if (!isNumberLast) { if (text == "(") { if (elements.Count > 0 && (ONP.isOperator(elements.Last()) || elements.Last() == "(")) { if (inputTextBox.Text.LastChar() == ",") { return; } inputTextBox.Text += "("; elements.Add(text); } else if (inputTextBox.Text == "0") { inputTextBox.Text = "("; elements.Add(text); } } else if (inputTextBox.Text == "0") { if (text == "-") { elements.Add(text); inputTextBox.Text = text; } } else if (inputTextBox.Text.Contains("=")) { elements.Add(result); elements.Add(text); inputTextBox.Text = result + text; result = ""; } else if (ONP.isOperator(text)) { if (inputTextBox.Text.Length > 0 && elements.Last() == ")") { elements.Add(text); inputTextBox.Text += text; } else { if (inputTextBox.Text.Length > 1 && elements.Last() == "(") { return; } else { elements.RemoveLast(); elements.Add(text); inputTextBox.Text = inputTextBox.Text.RemoveLastChar(); inputTextBox.Text += text; } } } else if (text == ")" && isBracketNeeded()) { elements.Add(text); inputTextBox.Text += text; } } else { if (ONP.isOperator(text) || (text == ")" && isBracketNeeded())) { elements.Add(currentNumber); currentNumber = ""; isNumberLast = false; elements.Add(text); inputTextBox.Text += text; } } MRclicked = false; }
private bool isANumber(string s) { return(!(ONP.isOperator(s) || s == "(" || s == ")")); }