More user-friendly control of user input (1 of n)

Source: Internet
Author: User

Restrict "fullwidth" input by setting.

A few years ago, I made a project on net 1.0. after delivery, the customer always said that the data obtained by fuzzy search is inaccurate. Check the code. No problem! Check the log. No problem! Run the test. No error is reported. Finally, I had to go to the customer to check whether the total number of thousands of documents entered per day would be 10 if I checked by destination, and if I entered it by operator (only one operator entered for one destination) check, the total number is 35, which is actually 35. God, what is it? I checked the database, and it turned out to be a fault caused by the Chinese input method. The correct destination address is "H.K. AirPort", but a large number of "H" appear in the database. K. AirPort ". Due to lack of experience at that time, this problem was solved by programming, and the punctuation marks in the string were automatically removed or replaced with halfwidth symbols. The Code has been written into a large segment, but the efficiency is very poor. In a few days, I got this solution on MSDN.

Now I recommend this method to you:Set the ImeMode attribute of Control to Control the status of the Input Method Editor (IME.

For example, in a form, there are two TextBox. The first TextBox (name = "cnTextBox", TabIndex = 0) requires the Chinese name, the second TextBox (name = "enTextBox", TabIndex = 1) must be in English. According to the user's habits, after entering cnTextBox, the focus will be switched to enTextBox. If the user does not switch the input method status, it is very likely that the enTextBox will be entered with a fullwidth character; in addition, frequent switching of input methods does not meet the requirements of quick input.

Then, we can set the attributes as follows:

CnTextBox. ImeMode = ImeMode. On;
EnTextBox. ImeMode = ImeMode. Disable;

Test the input method. No matter what the input method is, if the focus is on enTextBox, the input method stops working. when the focus is off enTextBox, the input method is restored to the status before the switch.

ImeModeThere are also multiple values, which have different uses (reference MSDN ):

Public enum ImeMode
{
Inherit, // Inherit the IME mode of the parent control.
NoControl, // none (default ).
On, // IME enabled. This value indicates that the IME is enabled and can contain Chinese or Japanese characters. This value is only valid for Japanese, simplified Chinese, and traditional Chinese IME.
Off, // IME is disabled. This mode indicates that the IME is disabled, which means that the object is in the same way as the English input mode. This value is only valid for Japanese, simplified Chinese, and traditional Chinese IME.
Disable, // IME is disabled. If this value is used, you cannot open IME from the keyboard and the IME floating window is hidden.
Hiragana, // hirakana DBC. This value is only valid for Japanese IME.
Katakana, // Katakana DBC. This value is only valid for Japanese IME.
KatakanaHalf, // katakanka SBC. This value is only valid for Japanese IME.
AlphaFull, // double-byte letter or number. This value is only valid for Korean and Japanese IME.
Alpha, // alphanumeric single-byte characters (SBC ). This value is only valid for Korean and Japanese IME.
HangulFull, // Korean DBC. This value is only valid for Korean IME.
Hangul, // Korean SBC. This value is only valid for Korean IME.
Close,
OnHalf
}

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.