Esempio n. 1
0
 // Извлечение корня
 private void bt_Root_Click(object sender, EventArgs e)
 {
     if (tb_Input.Text.Length < tb_Input.MaxLength)
     {
         InputExpression.AddBinaryOperation("Root");
     }
 }
Esempio n. 2
0
 private void bt_9_Click(object sender, EventArgs e)
 {
     if (tb_Input.Text.Length < tb_Input.MaxLength)
     {
         InputExpression.AddFigure('9');
     }
 }
Esempio n. 3
0
 // 1/x
 private void bt_DivideRevers_Click(object sender, EventArgs e)
 {
     if (tb_Input.Text.Length < tb_Input.MaxLength)
     {
         InputExpression.AddUnaryOperation("1 / ");
     }
 }
Esempio n. 4
0
        // Кнопки со знаками операций
        #region Arithmetics

        // Отрицание
        private void bt_Negote_Click(object sender, EventArgs e)
        {
            if (tb_Input.Text.Length < tb_Input.MaxLength)
            {
                InputExpression.Negate();
            }
        }
Esempio n. 5
0
 private void bt_Point_Click(object sender, EventArgs e)
 {
     if (tb_Input.Text.Length < tb_Input.MaxLength)
     {
         InputExpression.AddPoint();
     }
 }
Esempio n. 6
0
        // Вычисление значения выражения
        private void bt_Equal_Click(object sender, EventArgs e)
        {
            InputExpression.FinishInput();
            int i = 0;

            while (i < OperationSigns.Length && !tb_Input.Text.Contains(OperationSigns[i]))
            {
                i++;
            }
            // Если выражение содержит знаки операций
            if (i < OperationSigns.Length)
            {
                tb_RPNExpression.Text = Translation.TranslateExpression(tb_Input.Text);
                tb_Output.Text        = Calculation.CalculateExpression(tb_RPNExpression.Text);
            }
            // Если выражение не содержит знаки операций
            else
            {
                tb_RPNExpression.Text = tb_Output.Text = tb_Input.Text;
            }
        }
Esempio n. 7
0
        // Обработка нажатия клавиши
        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                // Числовые клавиши
                #region Figures
            case Keys.D1:
            case Keys.NumPad1:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('1');
                }
                break;

            case Keys.D2:
            case Keys.NumPad2:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('2');
                }
                break;

            case Keys.D3:
            case Keys.NumPad3:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('3');
                }
                break;

            case Keys.D4:
            case Keys.NumPad4:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('4');
                }
                break;

            case Keys.D5:
            case Keys.NumPad5:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('5');
                }
                break;

            case Keys.D6:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        InputExpression.AddBinaryOperation("^");
                    }
                    else
                    {
                        InputExpression.AddFigure('6');
                    }
                }
                break;

            case Keys.NumPad6:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('6');
                }
                break;

            case Keys.D7:
            case Keys.NumPad7:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('7');
                }
                break;

            case Keys.D8:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        InputExpression.AddBinaryOperation("*");
                    }
                    else
                    {
                        InputExpression.AddFigure('8');
                    }
                }
                break;

            case Keys.NumPad8:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('8');
                }
                break;

            case Keys.D9:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        InputExpression.AddOpeningParenthesis();
                    }
                    else
                    {
                        InputExpression.AddFigure('9');
                    }
                }
                break;

            case Keys.NumPad9:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('9');
                }
                break;

            case Keys.D0:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        InputExpression.AddClosingParenthesis();
                    }
                    else
                    {
                        InputExpression.AddFigure('0');
                    }
                }
                break;

            case Keys.NumPad0:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddFigure('0');
                }
                break;
                #endregion Figures

            // Клавиши с десятичным разделителем и знаками операций
            case Keys.Divide:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddBinaryOperation("/");
                }
                break;

            case Keys.Multiply:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddBinaryOperation("*");
                }
                break;

            case Keys.Subtract:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddBinaryOperation("-");
                }
                break;

            case Keys.Decimal:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddPoint();
                }
                break;

            case Keys.Add:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddBinaryOperation("+");
                }
                break;

            case Keys.OemMinus:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    InputExpression.AddBinaryOperation("-");
                }
                break;

            case Keys.Oemplus:
                if (tb_Input.Text.Length < tb_Input.MaxLength)
                {
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        InputExpression.AddBinaryOperation("+");
                    }
                    else
                    {
                        InputExpression.FinishInput();
                        int i = 0;
                        while (i < OperationSigns.Length && !tb_Input.Text.Contains(OperationSigns[i]))
                        {
                            i++;
                        }
                        // Если выражение содержит знаки операций
                        if (i < OperationSigns.Length)
                        {
                            tb_RPNExpression.Text = Translation.TranslateExpression(tb_Input.Text);
                            tb_Output.Text        = Calculation.CalculateExpression(tb_RPNExpression.Text);
                        }
                        // Если выражение не содержит знаки операций
                        else
                        {
                            tb_RPNExpression.Text = tb_Output.Text = tb_Input.Text;
                        }
                    }
                }
                break;

            case Keys.Back:
                InputExpression.DeleteSymbol();
                break;

            case Keys.Escape:
                InputExpression.Clear();
                tb_RPNExpression.Text = tb_Output.Text = "0";
                break;
            }
        }
Esempio n. 8
0
 // Очистить выражение
 private void bt_ClearAll_Click(object sender, EventArgs e)
 {
     InputExpression.Clear();
     tb_RPNExpression.Text = tb_Output.Text = "0";
 }
Esempio n. 9
0
        // Редактирование выражения
        #region Edit

        // Удалить последний символ выражения
        private void bt_Backspace_Click(object sender, EventArgs e)
        {
            InputExpression.DeleteSymbol();
        }