Keyboard Events
-
Im having a trouble to catch KeyDown event on the form.. it just doesnt work.. any other control on the form can get KeyDown event if ill set it to him but the form event just doesnt work.. thanks..
The form itself rarely ever has the focus. The controls on the form have it, so the form's KeyDown event is rarely ever called. Unless, that is, the Form's
KeyPreview
property is set totrue
. This will pass all the keyboard events going to the form's control with the focus to the form's handlers first, then pass them on to the control that has the focus. There is a side effect to setting this though. The KeyDown event will fire for every keystroke going to any control on your form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
The form itself rarely ever has the focus. The controls on the form have it, so the form's KeyDown event is rarely ever called. Unless, that is, the Form's
KeyPreview
property is set totrue
. This will pass all the keyboard events going to the form's control with the focus to the form's handlers first, then pass them on to the control that has the focus. There is a side effect to setting this though. The KeyDown event will fire for every keystroke going to any control on your form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
Hi, I'm curious, why would a form need to catch keyboard events? What are you using it for? I can't think of any scenario where this can be used. /Patric My C# blog: C# Coach
Im building a small program which you can get the color of any pixel on the screen, color picker after pointing on a pixel and getting its RGB and HEX into text boxes how would you remember them? just clicking on a button will get them into a list of colors :)
-
Actually, they did. Form.KeyPreview[^] RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome