Answered by:
Prevent a button to react on Enter key

Question
-
Answers
-
In keyDown event:
if(e.KeyCode != Keys.Enter) { //code will go in here if any key is press except Enter }
Mitja
- Proposed as answer by Ahmed Naji Saturday, March 3, 2012 12:23 PM
- Marked as answer by Pivskid Monday, March 5, 2012 9:38 AM
All replies
-
In keyDown event:
if(e.KeyCode != Keys.Enter) { //code will go in here if any key is press except Enter }
Mitja
- Proposed as answer by Ahmed Naji Saturday, March 3, 2012 12:23 PM
- Marked as answer by Pivskid Monday, March 5, 2012 9:38 AM
-
Hi,
If you are focused on the button and press 'enter' on the keyboard the 'Enter' keypress event doesn't raise (react) - but by pressing 'space' then it raises a buttonClick event and a keyPressEvent..
sounds a little confused.. but when does the 'enter' keyPress on a button raises that event?
Regards Muli
If some code doesn't work, don't worry help is on the way.. don't forget to mark your thread as solved when done...
-
Perhaps all that is necessary is to set the form's AcceptButton, as documented here: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx.
--
Mike- Proposed as answer by Neddy Ren Monday, March 5, 2012 6:44 AM
-