Key handler problem

  • Thread starter Thread starter Chuck Bowling
  • Start date Start date
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?
 
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
 
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.
 
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...
 
Back
Top