// Calculator_KeyPress: Checks for user input through KeyPresses and performs // the corresponding Click-event for the appropriate button. // Pre: - // Post: The KeyPress-event has been handled and, if there's a match, the appropriate // buttons Click-event has been fired. private void Calculator_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case '1': OneButton.PerformClick(); break; case '2': TwoButton.PerformClick(); break; case '3': ThreeButton.PerformClick(); break; case '4': FourButton.PerformClick(); break; case '5': FiveButton.PerformClick(); break; case '6': SixButton.PerformClick(); break; case '7': SevenButton.PerformClick(); break; case '8': EightButton.PerformClick(); break; case '9': NineButton.PerformClick(); break; case '0': ZeroButton.PerformClick(); break; case '/': DivideButton.PerformClick(); break; case '*': MultiplyButton.PerformClick(); break; case '-': SubtractButton.PerformClick(); break; case '+': AddButton.PerformClick(); break; case ',': CommaButton.PerformClick(); break; case 'C': ClearButton.PerformClick(); break; case 'c': ClearButton.PerformClick(); break; } e.Handled = true; }
private void Form1_KeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar.ToString()) { case ("0"): ZeroButton.PerformClick(); break; case ("1"): OneButton.PerformClick(); break; case ("2"): TwoButton.PerformClick(); break; case ("3"): ThreeButton.PerformClick(); break; case ("4"): FourButton.PerformClick(); break; case ("5"): FiveButton.PerformClick(); break; case ("6"): SixButton.PerformClick(); break; case ("7"): SevenButton.PerformClick(); break; case ("8"): EightButton.PerformClick(); break; case ("9"): NineButton.PerformClick(); break; case ("\r"): EqualsButton.PerformClick(); break; case ("."): PointButton.PerformClick(); break; case ("/"): DivideButton.PerformClick(); break; case ("*"): TimesButton.PerformClick(); break; case ("-"): MinusButton.PerformClick(); break; case ("+"): PlusButton.PerformClick(); break; } }