Search code examples
c#axwebbrowser

A button that can ONLY be used by clicking. No Enter, no Return. Just clicks


I wish I could throw a ! on a Google search, and turn up the opposite answer. Looking for having buttons NOT activated by keypresses only turns up folks who need their buttons activated by keypresses.

I'm having issues with buttons on a form being accidentally triggered by Enter & Return keypresses. They tend to have Focus on them, and keep firing while trying to press Enter in an unrelated part of the form (on a WebBrowser).

I thought to defend them with

 if (!btnButton1.Focused) { return; }

but as I said, Focus tends to linger on them, and this doesn't help me out

I want my buttons to only be usable through by clicks.


Solution

  • Just subscribe to the Button.MouseClick event instead of Button.Click.