0

This is ridiculous. I have a KeyDown event I am interested in(to get DownArrow Key event) for a WinForm. I added a trackbar, which gets Autofocus(I dont know how). And now, when I press the DOWN arrow key - it automatically changes the value of the Trackbar and my code for the Winform is not working. I tried HIDING the Trackbar with a button but to no avail. I even have

e.SuppressKeyPress = true;

in my Form1_KeyDown() handler.

Help, I am going haywire.

Aniket Inge
  • 25,375
  • 5
  • 50
  • 78

1 Answers1

0

You can override ProcessCmdKey method. check out below links for more information.

Up, Down, Left and Right arrow keys do not trigger KeyDown event

http://www.getdotnetcode.com/gdncstore/free/Articles/Overriding%20a%20Controls%20ProcessCmdKey%20Function.htm

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.processcmdkey(v=vs.85).aspx

Community
  • 1
  • 1
Jignesh Thakker
  • 3,638
  • 2
  • 28
  • 35
  • unfortunately, UP|DOWN|LEFT|RIGHT /are/ triggering KeyDown() events, and they're being consumed by Trackbar. I found a solution around it. It is to Override KeyDown() event for the trackbar and call Form1_KeyDown() event instead. – Aniket Inge Sep 22 '12 at 15:46
  • Have you checked with ProcessCmdKey() method? if you pressed any key on form this method will execute if you override it in your form codebehind file. – Jignesh Thakker Sep 22 '12 at 15:53