private void Lab1Form_KeyDown(object sender, KeyEventArgs e) { Keys kc = e.KeyCode; switch (e.KeyCode) { case Keys.D0: case Keys.NumPad0: if (e.Shift) { Btn_closeBracket.PerformClick(); } else { Btn_0.PerformClick(); } break; case Keys.D1: case Keys.NumPad1: Btn_1.PerformClick(); break; case Keys.D2: case Keys.NumPad2: Btn_2.PerformClick(); break; case Keys.D3: case Keys.NumPad3: Btn_3.PerformClick(); break; case Keys.D4: case Keys.NumPad4: Btn_4.PerformClick(); break; case Keys.D5: case Keys.NumPad5: Btn_5.PerformClick(); break; /* "^" */ case Keys.D6: case Keys.NumPad6: if (e.Shift) { Btn_power.PerformClick(); } else { Btn_6.PerformClick(); } break; case Keys.D7: case Keys.NumPad7: Btn_7.PerformClick(); break; case Keys.D8: case Keys.NumPad8: Btn_8.PerformClick(); break; case Keys.D9: case Keys.NumPad9: if (e.Shift) { Btn_openBracket.PerformClick(); } else { Btn_9.PerformClick(); } break; case Keys.Escape: Btn_clear.PerformClick(); break; case Keys.Enter: Btn_equal.PerformClick(); break; case Keys.Add: Btn_plus.PerformClick(); break; case Keys.Subtract: Btn_minus.PerformClick(); break; case Keys.Multiply: Btn_mul.PerformClick(); break; case Keys.Divide: Btn_div.PerformClick(); break; case Keys.Back: Btn_backspace.PerformClick(); var expr = Expression_tb; var result = Result_tb; string prep_expr = Calc.Prepare(expr.Text); if (Calc.TryExecute(prep_expr, out double res)) { result.Text = res.ToString(); } else { result.Text = ""; } break; } if (e.Shift && kc == Keys.Oemplus) { Btn_plus.PerformClick(); } else if (e.Shift && kc == Keys.OemMinus) { Btn_minus.PerformClick(); } }
//нажатие клавиш на клавиатуры private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.NumPad0) { Btn_0.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad1) { Btn_1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad2) { Btn_2.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad3) { Btn_3.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad4) { Btn_4.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad5) { Btn_5.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad6) { Btn_6.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad7) { Btn_7.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad8) { Btn_8.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.NumPad9) { Btn_9.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Multiply) { Btn_Multiply.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Add) { Btn_Plus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Divide) { Btn_Devide.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Subtract) { Btn_Minus.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Decimal) { Btn_Dot.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Enter) { Btn_Result.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.Back) { Btn_AC.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.D9) { Btn_Left.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } if (e.Key == Key.D0) { Btn_Right.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } }