Esempio n. 1
0
        private void OnCalculate(Object sender, EventArgs e)
        {
            this.Multiplication.BackgroundColor = Color.Gray;
            this.Division.BackgroundColor       = Color.Gray;
            this.Addition.BackgroundColor       = Color.Gray;
            this.Subtraction.BackgroundColor    = Color.Gray;

            if (currentState == 2)
            {
                var result = OperaterHelper.Calculate(firstNumber, secondNumber, myoperator);
                this.resultText.Text = result.ToString();
                OnSelectDot(this.resultText.Text);
                firstNumber  = result;
                currentState = -1;
            }
        }
Esempio n. 2
0
        void OnSelectOperator(Object sender, EventArgs e)
        {
            Button button  = (Button)sender;
            string pressed = button.Text;

            myoperator = pressed;

            if (pressed == "X")
            {
                this.Multiplication.BackgroundColor = Color.Orange;
                this.Division.BackgroundColor       = Color.Gray;
                this.Addition.BackgroundColor       = Color.Gray;
                this.Subtraction.BackgroundColor    = Color.Gray;
            }
            if (pressed == "/")
            {
                this.Multiplication.BackgroundColor = Color.Gray;
                this.Division.BackgroundColor       = Color.Orange;
                this.Addition.BackgroundColor       = Color.Gray;
                this.Subtraction.BackgroundColor    = Color.Gray;
            }
            if (pressed == "-")
            {
                this.Multiplication.BackgroundColor = Color.Gray;
                this.Division.BackgroundColor       = Color.Gray;
                this.Addition.BackgroundColor       = Color.Gray;
                this.Subtraction.BackgroundColor    = Color.Orange;
            }
            if (pressed == "+")
            {
                this.Multiplication.BackgroundColor = Color.Gray;
                this.Division.BackgroundColor       = Color.Gray;
                this.Addition.BackgroundColor       = Color.Orange;
                this.Subtraction.BackgroundColor    = Color.Gray;
            }


            if (currentState == 2)
            {
                var result = OperaterHelper.Calculate(firstNumber, secondNumber, myoperator);

                this.resultText.Text = result.ToString();
                //OnSelectComma(this.resultText.Text);
                firstNumber = result;
            }
            currentState = -2;

            if (str0.Length == 0)
            {
                if (myoperator == "-")
                {
                    if (this.resultText.Text == "0" || currentState < 0)
                    {
                        this.resultText.Text = "";
                        if (currentState < 0)
                        {
                            currentState *= -1;
                        }
                    }
                    this.resultText.Text += myoperator;
                    currentState          = 1;
                }
                else
                {
                    currentState = -2;
                }
            }
            d = 0;
        }