RightArrow loses focus rather than raising KeyDown event

T

Tony Lin

I have written a custom Windows control from scratch, deriving from the Windows.Forms.Control class.



My control has a text input area, capable of receiving focus. It has a KeyDown event handler, which handles Keys.Left, Keys.Right, Keys.Home, Keys.End.



When focus is on my custom control, pressing Left Arrow or Right Arrow shifts focus to the previous or the next control, rather than raising a KeyDown event in my custom control. The result is that my custom control never sees a KeyDown event with a KeyCode of Keys.Left or Keys.Right.



My custom control handles Keys.Home and Key.End just fine.



Does anyone know what I have to do, to have focus remain in my custom control when LeftArrow or RightArrow is pressed, so that my control handle that event?



Tony Lin

Fremont, CA
 
D

Duke Sun

Have you tried the Control.ProcessCmdKey Method?This method is called
during message preprocessing to handle command keys.
 
T

Tony Lin

Duke,

Your suggestion worked great!

I didn't realize that the control class had a whole set of "Processxxx"
methods for handling key stroke events.

I wish the documentation on KeyDown had mentioned this.

Thanks a lot.

Tony Lin
 

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