Theoretically, setting KeyPreview
property of the form to True
should do it. Then handle KeyDown
event, and make sure to set e.Handled
to True
on pressing the Enter key (or e.SuppressKeyPress, depends on implementation of controls you are working with).
I tried this approach in a sample project just now, however, and it did not work with a button for some reason. You may need to resort to using WndProc
on the form level, this always works 100%.