In fact, in the link provided by seaman_x, we have introduced in quite detail how to control the Input Method in winform. For the two questions you are concerned about, that is, how to obtain all the input methods in the system, and how to select a specific input method based on the input language and other special requirements, the following section usesProgramThe parts are further described.
1) traverse all input methods in the system and use the following program snippets:
Foreach (inputlanguage Lang in inputlanguage. installedinputlanguages)
{
This. textbox1.text + = "\ r \ nname>" + Lang. layoutname + "\ r \ nculture>" + Lang. Culture. Name + "\ r \ n ";
}
The running result is similar:
Name> Chinese (simplified)-Microsoft Pinyin IME 3.0
Culture> ZH-CN
Name> Chinese (simplified)-US keyboard
Culture> ZH-CN
Name> Chinese (traditional)-New phonetic
Culture> ZH-TW
Name> Japan Input System (MS-IME2002)
Culture> ja-JP
Name> Chinese (traditional)-US keyboard
Culture> ZH-TW
Name> Japan
Culture> ja-JP
After obtaining all input methods in the system, you can select a specific input language and input method through culture and name.
2) switch to the simplified Chinese Input Method
If (inputlanguage. defaultinputlanguage. layoutname. indexof ("keyboard") =-1 & inputlanguage. defaultinputlanguage. Culture. Name. Equals ("ZH-CN "))
{
Inputlanguage. currentinputlanguage = inputlanguage. defaultinputlanguage;
}
Else
{
Foreach (inputlanguage Lang in inputlanguage. installedinputlanguages)
{
If (Lang. Culture. Name. Equals ("ZH-CN") & Lang. layoutname. indexof ("keyboard") =-1)
{
Inputlanguage. currentinputlanguage = Lang;
Break;
}
}
}
In this program, first determine the system default input method. If the default input method is ZH-CN and the input method name does not contain the word "keyboard, the default input method is a simplified Chinese Input Method, and is not "Chinese (simplified)-US keyboard". Then, the system uses the default input method as the current input method.
If the preceding conditions are not met, traverse all input methods installed in the system, use the input method that contains the first type of culture ZH-CN and does not contain the word "keyboard" as the current input method.