Onkeydown and direction keys of. Net winform

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.