Exemplo n.º 1
0
        private void calc_KeyUp(object sender, KeyEventArgs e)
        {
            Keys keyCode  = e.KeyCode;
            int  keyValue = e.KeyValue;

            if (keyCode >= Keys.D0 && keyCode <= Keys.D9)
            {
                calculator.addDisplayNumber((keyValue - ((int)Keys.D0)));
            }
            else if (keyCode >= Keys.NumPad0 && keyCode <= Keys.NumPad9)
            {
                calculator.addDisplayNumber((keyValue - ((int)Keys.NumPad0)));
            }
            else if (keyCode == Keys.Delete)
            {
                calculator.removeDisplays();
            }
            else if (keyCode == Keys.Back)
            {
                calculator.removeLastDisplayNumber();
            }
            else if (keyCode == Keys.Add)
            {
                calculator.addOperator((char)Calculator.Symbols.ADD);
            }
            else if (keyCode == Keys.Subtract)
            {
                calculator.addOperator((char)Calculator.Symbols.SUBSTRACT);
            }
            else if (keyCode == Keys.Multiply)
            {
                calculator.addOperator((char)Calculator.Symbols.MULTIPLY);
            }
            else if (keyCode == Keys.Divide)
            {
                calculator.addOperator((char)Calculator.Symbols.DIVIDE);
            }
            else if (keyCode == Keys.Decimal || keyCode == Keys.Oemcomma)
            {
                calculator.appendDisplayComma();
            }
            else if (keyCode == Keys.Return)
            {
                calculator.calculateResult();
            }
            printDisplays(calculator.getDisplays());
        }