In the development of WinForm, there are sometimes special requirements. For example: In a form to completely block the Chinese input method, so that it can not switch to Chinese input, can not be entered in Chinese.
The problem looks simple and is not as simple as it might seem. Below, I do a few of the experiments listed in turn, you will find that in fact, it is still difficult to achieve.
Experiment One:
1, the new project, the establishment of two form, respectively, Form1, Form2. Form1 is the start form.
2. There is a TextBox and a button on the Form1.
Click the button to execute the following statement
Me.hide ()
Form2.show ()
3, Form2 has a textbox,textbox of the IMEMode property set to close, meaning to turn off input mode.
Execute the following statement in the Form2 formclosed event.
Form1.show ()
OK, now to test the experiment. Well, unfortunately, in the Form2 in the textbox is very smooth switch the Chinese input method, entered the Chinese. The test failed.
Experiment Two:
Continue to experiment one, find the relevant data, found that there is a inputlanguagechanging event, seems to be able to control the input method of the switch.
4, add the following code in the Inputlanguagechanging event of the Form2 textbox
E.cancel = True
To test. Seemingly successful, according to the test, the Form2 in the textbox can not switch the input method.
Why does it seem like it? We'll test it again, and we'll have a problem.
First in the Form1 in the textbox to switch to Chinese input method. Then click on the button, switch to Form2, you ctrl+space, found in the textbox in Form2 appeared familiar with the Chinese input method. Oh, experiment II can not be counted as successful.
Why does the analysis experiment two not succeed. I think the key is to switch to Form2 before I have switched to Chinese input method. So what if you pin the input method to the default input method of the system before switching Form2?