Search code examples
vb.netuser-controlsscrollbarkeypress

How can I prevent key presses from changing the value of a scrollbar control?


I have a form with a user control that has a vscrollbar control. I would like to handle the user control's keypress event, but when I press the 'down arrow' key (for example), the keypress event isn't handled, and the vscrollbar's value increases instead. Other navigational keys behave this way as well.

I would like to have the vscrollbar stop 'overriding' my intention to raise the keypress event. I was thinking I could set the user control's keypreview property to true, but then I noticed it doesn't have one.


Solution

  • You need to look at using the KeyDown or PreviewKeyDown event instead.