Processing up/down arrow at form level

R

Rachel Suddeth

I have a grid on all my basic data entry forms, and I want Up/Down arrow to
navigate the grid no matter where the focus is on the form. I have
form.KeyPreview set to true (because I want the form to get the key events
first), and trap the arrows in the KeyDown event for the form. This works
fine until a button is clicked with the mouse. Once the focus is on a
button, the up/down arrows no longer do anything to the grid. If the focus
is moved to a textbox or checkbox, then it works fine again.

There is a note in some of the help files that may provide a clue to what's
wrong, but I can't understand what it means:
Certain keys, such as the TAB, RETURN, ESCAPE,
and arrow keys are handled by controls automatically.
In order to have these keys raise the KeyDown event, you
must override the IsInputKey method in each control on
your form. The code for the override of the IsInputKey
would need to determine if one of the special keys is pressed
and return a value of true.

I don't understand what it means to "override" this method in the controls
on my form. In order to override, I have to be creating a derived class,
right? So this means I would not be able to put any control on my form
unless I first wrote a class derived from some control, and I could only put
them on my form? (Actually, I do this anyway, so no big deal, but I think I
tried overriding IsInputKey in the base class and it didn't work.) And why
each control? Most of the controls are not swallowing the key events (at
least not for the arrow keys.) In fact, why should I have to do anything to
the controls to get this behavior when the form.KeyPreview is supposed to
cause the events to go the form first. How can the controls on the form
swallow the events before the form gets them if the form gets them first?

Any advice would be appreciated...
-Rachel
______________________________________________________________
Roydan Enterprises Ltd
602 North 9th Street Manitowoc,
WI 54220-3924
 
R

Rachel Suddeth

Stefan, this is really great, thank you (I thought I sent this reply before
but it didn't show up?) It works perfectly, and I also had wrote some custom
shortcuts (hot keys) for tab pages and it's all working great running from
ProcessCmdKey().

What does HTH mean?
-Rachel
 

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