With a small handwritingProgram, Suddenly encountered a problem:
In a custom control, override uses an onkeydown to process direction keys. The result is invalid. The trace debugging finds that the direction key cannot enter the function breakpoint, but other keys such as numbers and letters can.
I checked it online and found that many people encountered the same problem. However, it is not in a custom control, but in a form. Of course, the solution is simple. Set keypreview to true.
Custom controls do not have the keypreview attribute.
Why is the direction key so special? It is very simple. Originally, the arrow keys and tabulation keys (tabs) were used to switch the focus of each child control in the form. Therefore, they were intercepted and processed before the onkeydown.
Once you know the reason, it's easy to solve it:
If you need to process the direction keys in a custom control, you can override onpreviewkeydown/onpreviewkeyup and other ills.