Пример #1
0
        private void Button_Click(object sender, EventArgs e)
        {
            var    button = sender as Button;
            double number = 0;

            if (double.TryParse(button.Text, out number))
            {
                if (OperationActive)
                {
                    CalculatorField.Clear();
                    OperationActive = false;
                }
                if (CalculatorField.Text == "0" || CalculatorField.Text == "∞" || CalculatorField.Text == "-∞")
                {
                    CalculatorField.Text = button.Text;
                }
                else
                {
                    CalculatorField.Text += button.Text;
                }
                return;
            }

            switch (button.Text)
            {
            case "+":
                OperationActive = true;
                SetResult(ArithmeticOperations.GetResult(button.Text, double.Parse(CalculatorField.Text)));
                break;

            case "-":
                OperationActive = true;
                SetResult(ArithmeticOperations.GetResult(button.Text, double.Parse(CalculatorField.Text)));
                break;

            case "*":
                OperationActive = true;
                SetResult(ArithmeticOperations.GetResult(button.Text, double.Parse(CalculatorField.Text)));
                break;

            case "/":
                OperationActive = true;
                SetResult(ArithmeticOperations.GetResult(button.Text, double.Parse(CalculatorField.Text)));
                break;

            case "=":
                SetResult(ArithmeticOperations.GetResult(button.Text, double.Parse(CalculatorField.Text)));
                break;

            case ".":

                if (OperationActive)
                {
                    return;
                }

                for (int i = 0; i < CalculatorField.Text.Length; i++)
                {
                    if (CalculatorField.Text[i] == '.')
                    {
                        return;
                    }
                }

                CalculatorField.Text += ".";
                break;

            default:
                MessageBox.Show("Что-то пошло не так...");
                break;
            }
        }
Пример #2
0
 private void ButtonDelete_Click(object sender, EventArgs e)
 {
     CalculatorField.Clear();
     ArithmeticOperations.Reset();
     CalculatorField.Text = "0";
 }