Example #1
0
        private void tb_console_one_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)//запрет ввода пробела
            {
                e.Handled = true;
            }
            if (e.Key == Key.Enter)
            {
                try
                {
                    string input = tb_console_one.Text;

                    if (input != String.Empty)
                    {
                        tb_console_one.Text = ReversePolishNotation.PerformCalculations(input).ToString();
                        tb_console_two.Text = input + "=";
                        tb_console_one.Focus();
                    }
                }
                catch (FormatException ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("Неверный ввод: ");
                    sb.Append(ex.Message);
                    MessageBox.Show(sb.ToString(), "Warning");
                    tb_console_one.Focus();
                }
                catch (DivideByZeroException)
                {
                    MessageBox.Show("Деление на ноль", "Warning");
                    tb_console_one.Focus();
                }
            }
        }
Example #2
0
        private void button_res_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string input = tb_console_one.Text;

                if (input != String.Empty)
                {
                    tb_console_one.Text = ReversePolishNotation.PerformCalculations(input).ToString();
                    tb_console_two.Text = input + "=";
                    tb_console_one.Focus();
                }
            }
            catch (FormatException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("Неверный ввод: ");
                sb.Append(ex.Message);
                MessageBox.Show(sb.ToString(), "Warning");
                tb_console_one.Focus();
            }
            catch (DivideByZeroException)
            {
                MessageBox.Show("Деление на ноль", "Warning");
                tb_console_one.Focus();
            }
        }