protected override bool ProcessCmdKey(ref Message msg, Keys key_data) { switch (key_data) { case Keys.Enter: Btn_equal.PerformClick(); return(true); } return(base.ProcessCmdKey(ref msg, key_data)); }
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(); } }