[C#] Problem with Handling keys when Button exists

Started by
1 comment, last by deathtrap 20 years, 5 months ago
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?
Advertisement
Try setting the buttons tabstop property to false, or use the windows API GetAsyncGetState function.
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.

This topic is closed to new replies.

Advertisement