コード例 #1
0
        /*Functionality Added to make the calculator work with Keyboard NumberPad
         * When the correct Key is detected it will fire off the corresponding button press*/
        private void Window_KeyDownPreview(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.NumPad0:
                Zero.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad1:
                One.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad2:
                Two.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad3:
                Three.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad4:
                Four.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad5:
                Five.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad6:
                Six.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad7:
                Seven.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad8:
                Eight.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.NumPad9:
                Nine.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Add:
                Plus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Subtract:
                Minus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Multiply:
                Multiply.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Divide:
                Divide.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;

            case Key.Enter:
                Equals.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                break;
            }
        }