Example #1
0
        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;
        }
Example #2
0
 private bool isANumber(string s)
 {
     return(!(ONP.isOperator(s) || s == "(" || s == ")"));
 }