Key handler problem

C

Chuck Bowling

I'm got a little problem that I can't figure out. I have a UserControl and
I'm trying to detect the Shift key. I'm using KeyUp and KeyDown event
handlers to set a flag when the Shift key is pressed. My problem is that the
handlers aren't getting called. I have the handlers registered with the
control and I don't know what else to try. Anybody got an idea what the
problem might be?
 
R

Rodger Constandse

If your UserControl has any child controls, they could be the ones getting the
KeyDown/KeyUp events rather than the UserControl itself. This can happen if any
of the child controls gets the focus.

If that is the case, you can hook the KeyDown/KeyUp of all child controls
recursively to detect when the Shift key is pressed in any of them.

Hope this helps
 
C

Chuck Bowling

Thanks Rodger, I'll give it a try.

Rodger Constandse said:
If your UserControl has any child controls, they could be the ones getting
the KeyDown/KeyUp events rather than the UserControl itself. This can
happen if any of the child controls gets the focus.

If that is the case, you can hook the KeyDown/KeyUp of all child controls
recursively to detect when the Shift key is pressed in any of them.

Hope this helps

--
Rodger

<http://www.SequenceDiagramEditor.com>
Sequence Diagram Editor - A quick and easy way to draw and edit sequence
diagrams.
 
C

Chuck Bowling

Small FYI, it turns out that all you have to do to detect the Shift key in
an event handler is to use the Control.ModifierKeys property...
 

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