mardi 3 mars 2015

How to detect ENTER key on button

I am using this code. panelButtons[] is an array of buttons.



for (i = 0; i <= 15; i++)
{
int temp = i;
panelButtons[temp].KeyPress += new KeyPressEventHandler(checkKeyPress);
}
}
private void checkKeyPress(object a, KeyPressEventArgs b)
{
if(b.KeyChar==(char)Keys.Enter || b.KeyChar==(char)Keys.Return)
{
DialogResult result = MessageBox.Show("Enter");
}
}


The problem is that, it is NOT detecting enter key. I have searched a lot on net, but all I get is how to detect ENTER key on textbox. This method, and many other similar to this(like KeyDown idea) are not working.


Aucun commentaire:

Enregistrer un commentaire