Assuming that you have buttons for numbers and mathematical operations, you may also do the following:
- Set the form's
KeyPreview
property to true
- Add an
OnKeyPress
event handler to the form
- Handle any key necessary
The code to handle the key press could look like:
if (e.KeyChar == '0')
{
e.Handled = true;
btn0.PerformClick();
}
That means: If the '0'-Key is pressed, programmatically push the button that stands for 0
. You can handle *
, /
etc. in the same way.
EDIT
Of course I assume that you have assigned a click event to the respective buttons that already do what you want to do (e.g. add number to display, perform operation on numbers and display result, etc.).