Archived

This topic is now archived and is closed to further replies.

[C#] Problem with Handling keys when Button exists

This topic is 5148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

good day, I''m having a problem using forms with C# and .NET . I can handle keys fine using the method: protected override void OnKeyDown(KeyEventArgs e) but when I include a simple button on the form I am unable to handle keys anymore, using that function, or OnKeyPress method, or even when adding the OnKeyDown and/or OnKeyPress methods to the form.KeyDown or form.KeyPress event handler(and yes I know that I had to change the argument list to add them to the event handlers). Could anyone try and clarify why this is happening please?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try setting the buttons tabstop property to false, or use the windows API GetAsyncGetState function.

Share this post


Link to post
Share on other sites
Hmm it works like that. It also works when I set the OnKeyDown event handler for the button.

I think the problem is that when I press escape or any key when the button has the current focus the buttons OnKeyDown event handler recieves it rather than the forms OnKeyDown handler.
thanks for the help.

Share this post


Link to post
Share on other sites