Problem with workaround to enable use of keyboard shortcuts

J

jd_ie

Hi all.

I have an application on a windows ce .net device which has a keyboard.
It has function keys (F1, F2, etc) and it is quite nice to use these
keys in a context-sensitive way so that the user can press them to
activate buttons in the application rather than clicking on the buttons
with the stylus. So far so good.

I am catching the KeyDown event for the forms and for any other
controls that I can, to catch when the user presses one of these
buttons. I had the problem that I could not catch these events when
certain control types (for example buttons) had the focus (a button
might get the focus for example if the user clicked within its bounds
but then dragged to outside its bounds before releasing). My workaround
was to catch the GotFocus method of these problem controls, and set a
timer (of 1 second or so) which when triggered would remove the focus
from the problem control and set it to the current Form. This seemed to
work fine. My first question is, is there a better way to do this?

I thought it worked fine until I saw that if an unhandled exception
occurred right after the user clicked a button, the error modal form
would pop up in front, but then after the one second it would disappear
behind as the current form got the focus in the timer_Tick method. Thus
the user sees this pop up and disappear again, which is not desirable
behaviour.

Is there any way in the timer_Tick method to determine whether there is
a form in front, and if so, to move it again to the front after I have
set the focus to the current form? Or is there another way to make the
keyboard buttons work when a button has the focus which would mean that
my second problem would not occur?

Thanking you all for any help,

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top