Пример #1
0
        private void TextBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            int val;

            if (!Int32.TryParse(e.Text, out val) && e.Text != ".")
            {
                e.Handled = true; // отклоняем ввод
            }

            if (string.Compare(e.Text, "*") == 0)                                //Сравнение строки
            {
                Multiply.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); //Запускаем метод нажатия на кнопку
            }

            //Нажатие деления
            if (string.Compare(e.Text, "/") == 0)//Сравнение строки
            {
                division.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
            }

            //Нажатие вычитания
            if (string.Compare(e.Text, "-") == 0)//Сравнение строки
            {
                Minus.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
            }

            //Нажатие сложения
            if (string.Compare(e.Text, "+") == 0)//Сравнение строки
            {
                Plus.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
            }
        }
Пример #2
0
        //OFF


        /*************************************************************
        *  Obsługa przycisków
        *************************************************************/
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.D1 || e.Key == Key.NumPad1)
            {
                One.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D2 || e.Key == Key.NumPad2)
            {
                Two.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D3 || e.Key == Key.NumPad3)
            {
                Three.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D4 || e.Key == Key.NumPad4)
            {
                Four.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D5 || e.Key == Key.NumPad5)
            {
                Five.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D6 || e.Key == Key.NumPad6)
            {
                Six.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D7 || e.Key == Key.NumPad7)
            {
                Seven.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D8 || e.Key == Key.NumPad8)
            {
                if (Keyboard.IsKeyDown(Key.LeftShift))
                {
                    Star.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }
                else
                {
                    Eight.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }
            }
            else if (e.Key == Key.D9 || e.Key == Key.NumPad9)
            {
                Nine.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.D0 || e.Key == Key.NumPad0)
            {
                Zero.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }

            /**********************************************************/

            /*else if (e.Key == Key.Enter)
             * {
             *  Equals.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
             * }*/
            else if (e.Key == Key.OemComma || e.Key == Key.OemPeriod || e.Key == Key.Decimal)
            {
                Dot.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
            {
                Minus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.OemPlus || e.Key == Key.Add)
            {
                Plus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Delete)
            {
                AC.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Back)
            {
                C.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Divide || e.Key == Key.OemBackslash || e.Key == Key.OemQuestion || e.Key == Key.Oem5)
            {
                Slash.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Multiply)
            {
                Star.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.P)
            {
                MP.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
            }
            else if (e.Key == Key.Escape)
            {
                Application.Current.Shutdown();
            }
            Console.WriteLine(e.Key.ToString());
        }