How can I determine which value is pressed by the keyboard?

Source: Internet
Author: User

In C #, the keycode and keyValue can be used to obtain the value you entered from the keyboard. For example:

Private void textbox3_keyup (Object sender, system. Windows. Forms. keyeventargs E)

{

Textbox1.text = E. keycode. tostring ();

Textbox2.text = E. keyValue. tostring ();

}

In this way, you can enter characters in textbox1 and textbox2 to view the corresponding keyboard code and keyboard value.

You may find out, why do textbox1 display uppercase letters after entering uppercase and lowercase characters? In fact, in. net, keys only have upper-case letters and no lower-case letters, so only lower-case letters can be displayed. To solve this problem, use keypresseventargs. Is to use the keypress event of textbox2. The Code is as follows:

Private void textbox2_keypress (Object sender, system. Windows. Forms. keypresseventargs E)

{

Textbox1.text = E. keychar. tostring ();

}

This will show lower case, but it can only show characters (note that E. keychar is char type), so it can only show A-Z, A-Z.

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.