コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            int digit  = -1;

            if (int.TryParse(button.Content.ToString(), out digit))
            {
                calc.AddDigit(digit);
            }
            else
            {
                switch (button.Tag)
                {
                case "plus":
                    calc.AddOperation(CalculatorOperation.Add);
                    break;

                case "minus":
                    calc.AddOperation(CalculatorOperation.Sub);
                    break;

                case "multiplication":
                    calc.AddOperation(CalculatorOperation.Mul);
                    break;

                case "division":
                    calc.AddOperation(CalculatorOperation.Div);
                    break;

                case "negate":
                    calc.TransformInput(CalculatorTransformation.Negate);
                    break;

                case "percent":
                    calc.TransformInput(CalculatorTransformation.Percent);
                    break;

                case "sqr":
                    calc.TransformInput(CalculatorTransformation.Sqr);
                    break;

                case "sqrt":
                    calc.TransformInput(CalculatorTransformation.Sqrt);
                    break;

                case "inverse":
                    calc.TransformInput(CalculatorTransformation.Inverse);
                    break;

                case "point":
                    calc.AddPoint();
                    break;

                case "compute":
                    calc.Compute();
                    break;

                case "delete":
                    calc.Delete();
                    break;

                case "clear":
                    calc.Clear();
                    break;

                default:
                    MessageBox.Show(button.Tag?.ToString() ?? "");
                    break;
                }
            }
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int    digit = -1;
            Button b     = sender as Button;

            if (int.TryParse(b.Content.ToString(), out digit))
            {
                calc.AddDigit(digit);
            }
            else
            {
                switch (b.Tag)
                {
                case "div":
                    calc.AddOperation(CalculatorOperation.Div);
                    break;

                case "mul":
                    calc.AddOperation(CalculatorOperation.Mul);
                    break;

                case "min":
                    calc.AddOperation(CalculatorOperation.Sub);
                    break;

                case "pls":
                    calc.AddOperation(CalculatorOperation.Add);
                    break;

                case "clear":
                    calc.Clear();
                    break;

                case "clearall":
                    calc.clearAll();
                    break;

                case "compute":
                    calc.Compute();
                    break;

                case "dot":
                    calc.AddPoint();
                    break;

                case "negate":
                    calc.TransformInput(CalculatorTransformation.Negate);
                    break;

                case "percent":
                    calc.TransformInput(CalculatorTransformation.Percent);
                    break;

                case "sqr":
                    calc.TransformInput(CalculatorTransformation.Sqr);
                    break;

                case "sqrt":
                    calc.TransformInput(CalculatorTransformation.Sqrt);
                    break;

                case "inverse":
                    calc.TransformInput(CalculatorTransformation.Inverse);
                    break;

                case "del":
                    calc.RemoveDigit();
                    break;
                }
            }
        }