all groups > dotnet windows forms > march 2007 >
You're in the

dotnet windows forms

group:

How to get arrow keys?


How to get arrow keys? Richard Lewis Haggard
3/31/2007 9:38:16 PM
dotnet windows forms:
I have a user control for which I'm trying to intercept arrow keys. I've
subscribed to both the KeyDown and KeyPress events. Normal keys are
delivered through the KeyPress event handler but arrow keys are not
delivered here. They do arrive at the KeyDown event but only if the control
key is also down. What am I doing wrong?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Re: How to get arrow keys? Richard Lewis Haggard
4/1/2007 6:44:16 PM
That's better but it still isn't working. The system is still getting in and
overriding my own set focus commands.

An arrow key is being handled in a manner much like it would with an array
of radio buttons within a group. Up and left arrows go to the previous
control in the Z order. Down and right shift focus to the control next in
the Z order despite the fact that the program is setting the TabStop
property of the windows to false.

The PreviewKeyDown event is, indeed, fired on key although the IsInputKey is
false, not true for cursor keys so I can now detect the user's cursor keys.
I then set the focus to the appropriate control but the system then
immediately turns around and sets it to the control it wants to. How can I
stop the system from setting focus?

--
Richard Lewis Haggard
www.Haggard-And-Associates.com

[quoted text, click to view]

Re: How to get arrow keys? Chris Taylor
4/1/2007 8:27:02 PM
Hi,

Controls assume that the arrow are used to navigate between controls. By
handling the PreviewKeyDown event and setting the
PreviewKeyDownEventArgs.IsInputKey to true when the
PreviewKeyDownEventArgs.KeyCode is one of the arrow keys you are interested
in, allows the message to be handled by the KeyDown/KeyUp events.

Hope this helps

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


[quoted text, click to view]
Re: How to get arrow keys? Chris Taylor
4/2/2007 12:00:00 AM
Hi,

Maybe you can explain what it is that you what to achieve, are you trying to
control the navigation programatically? If so then you should be looking at
the ProcessDialogChar/ProcessDialogKey virtual functions.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


[quoted text, click to view]
Re: How to get arrow keys? Richard Lewis Haggard
4/2/2007 2:37:23 PM
Thanks. That is precisely what I am trying to achieve. I want the user to be
able to use a right arrow to go to the control to the right of the current
control, up arrow to go to the one above and so on. I will try to make use
of the ProcessDialogxxx functions and see if that will stop the system from
using Z order to set focus to a control despite my own processing of the
event.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

[quoted text, click to view]

AddThis Social Bookmark Button