Beispiel #1
0
        private void ButtonOperator_Click(object sender, RoutedEventArgs e)
        {
            Button OperationButton = sender as Button;
            string Operation       = OperationButton.Name;


            if (double.TryParse(Operand2.Text, out double Operand2Num) && double.TryParse(Operand1.Text, out double Operand1Num))
            {
                switch (Operation)
                {
                case "ButtonAdd":
                    Answer.Text = Convert.ToString(Operand1Num + Operand2Num);
                    break;

                case "ButtonSubtract":
                    Answer.Text = Convert.ToString(Operand1Num - Operand2Num);
                    break;

                case "ButtonDivide":
                    if (Operand2Num == 0)
                    {
                        DivideByZeroError DivByZeroErrorWin = new DivideByZeroError();
                        DivByZeroErrorWin.Show();
                        Operand2.Focus();
                    }
                    else
                    {
                        Answer.Text = Convert.ToString(Operand1Num / Operand2Num);
                    }
                    break;

                case "ButtonMultiply":
                    Answer.Text = Convert.ToString(Operand1Num * Operand2Num);
                    break;

                default:
                    Answer.Text = "???";
                    break;
                }
            }
            else
            {
                ValidationError1 ValidationErrorWin = new ValidationError1();
                ValidationErrorWin.Show();
            }
        }