Reputation: 53
For a certain inputform, I'd like to make it possible to do input with the keyboard. I know how to read the keys through KeyPressed and KeyUp, but the problem is that when a control has got the focus and the user presses the Enter key, that control receives the a Click event. Is it possible to prevent that behaviour ? Or is it possible to know if a Click Event was fired by the mouse or by the keyboard ?
Upvotes: 2
Views: 523
Reputation: 5575
This would be easier if you could describe the situation and exact behaviour you want... :)
You can set:
Form.KeyPreview = True
This sends Key Events to the Form first, and then to the Control. This gives you the opportunity to catch Key Events on the form and 'cancel' them:
e.Handled = True
Also make sure you haven't set the AcceptButton for the Form!
Upvotes: 2
Reputation: 49731
Does this help? From Microsoft Knowledge Base
Move the Button's code from the button.Click() to a button.MouseClick()
Upvotes: 2