C # Control Input Method

Source: Internet
Author: User

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.

 

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.