I\'m trying to do a calculator and all I have to do is make it work with the keyboard. This should work but it doesn\'t.
private void Form1_KeyDown(objec
Assuming you have a WinForms project, set the KeyPreview property of your form to true, like that (e.g. in the constructor) :
public Form1()
{
InitializeComponent();
KeyPreview = true;
}
and it should work like you expected.
Edit: Due to your comment I've added the code to catch all the signs (add that to your Form1_KeyDown method)
if (((e.KeyCode == Keys.D7) && (e.Modifiers == Keys.Shift)) || (e.KeyCode == Keys.Divide))
{
sign("/");
}
else if (((e.KeyCode == Keys.Oemplus) && (e.Modifiers == Keys.Shift)) || (e.KeyCode == Keys.Multiply))
{
sign("*");
}
else if ((e.KeyCode == Keys.OemMinus) || (e.KeyCode == Keys.Subtract))
{
sign("-");
}
else if ((e.KeyCode == Keys.Oemplus) || (e.KeyCode == Keys.Add))
{
sign("+");
}
else if (e.KeyCode == Keys.Enter)
{
sign("=");
}