1 to traverse all the input methods in the system, you can use the following program fragment:
foreach (InputLanguage lang in inputlanguage.installedinputlanguages) {
This.textBox1.Text + = "\r\nname>" +lang. Layoutname+ "\r\nculture>" +lang. Culture.name + "\ r \ n";
}
After you get all the input methods in the system, you can select specific input languages and input methods through culture and name.
2) switch to 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 of all, the system default input method to judge, if the default input method culture is ZH-CN, and input method name does not contain "keyboard" words, the default input method is a simplified Chinese input method, and is not "Chinese (Simplified)-US Keyboard", then the system default input method as the current input method.
If the above conditions are not met, all the input methods installed in the system are traversed, the first type of culture encountered when traversing is ZH-CN and the input method name does not contain the word "keyboard" as the current input method.