RightArrow loses focus rather than raising KeyDown event

  • Thread starter Thread starter Tony Lin
  • Start date Start date
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
 
Have you tried the Control.ProcessCmdKey Method?This method is called
during message preprocessing to handle command keys.
 
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
 
Back
Top