How to get the native installation input method in C # Winform, and set it as the default output language, how to open Sogou ime and tablet

Source: Internet
Author: User

Original: How to get the native installation input method in C # Winform, and set as the default output language, how to open Sogou Input method and tablet

First, the question:

Today, I've sorted out two questions.

1, how to get the native installation of all input methods, and set to the system output language

2, how to open sogou Pinyin Input Method toolbar and tablet:

Second, the solution

For example: We want to set the Sogou IME input language for the native, how to use code to achieve it?

 //  Get all installed input methods     Inputlanguagecollection langs = inputlanguage.installedinputlanguages;  //  Loop through the Input method collection  foreach  (inputlanguage lang in   langs) { //  If it's Sogou ime  
   
    if  (lang. LayoutName = = 
     " 
     Chinese (Simplified)-sogou Pinyin Input Method  
     " 
    ) { 
    //
     set system by default select Sogou ime  inputlanguage.currentinputlanguage =
     Lang; }    }
   

For example: We want to open the Sogou Input Method toolbar and tablet, how to use the program code to open it?

    // start the handwriting program    System.Diagnostics.Process.Start (@ "C:\Program Files (x86) \sogouinput\components\handinput\1.1.0.282 \handinput.exe");     // start the Input method tool    System.Diagnostics.Process.Start (@ "C:\Program Files (x86) \sogouinput\8.4.0.1039\sgtool.exe ");

Ps: Open Sogou Input Method tool and handwriting need to install Sogou input method, to ensure consistent version (the above version of the corresponding folder name to your native name on the line)

Iii. Examples of integration

1. Interface design

Button class: Btngetinput, Btnsetinput, Btnopenhand, Btnopeninput

ListBox class: List_showinput

Ps: Open Input method of the tablet and input method premise guarantee version consistent

2, the overall code implementation

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewindowsforms{ Public Partial classForm2:form { PublicForm2 () {InitializeComponent (); }        /// <summary>        ///to obtain a locally installed input method/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidBtngetinput_click (Objectsender, EventArgs e) {            //get all the input methods for native installationInputlanguagecollection langs =inputlanguage.installedinputlanguages; //looping through all input methods            foreach(InputLanguage Langinchlangs) {                //determine if a ListBox has duplicate values                if(! This. List_showInput.Items.Contains (lang. LayoutName)) {//Add to ListBox                     This. List_showInput.Items.Add (lang.                LayoutName); }                       }        }        /// <summary>        ///set selected IME as system default Input Method/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidBtnsetinput_click (Objectsender, EventArgs e) {            //get all the input methods for native installationInputlanguagecollection langs =inputlanguage.installedinputlanguages; //determine if the ListBox selected collection must be greater than 0            if( This. List_showInput.SelectedItems.Count >0)            {                //Check the value selected in the ListBox                stringSelectedText = This. list_showInput.SelectedItem.ToString (); //Traverse Input Method                foreach(InputLanguage Langinchlangs) {                    if(lang. LayoutName = =SelectedText) {                        //Set system default Check IMEInputlanguage.currentinputlanguage =Lang; }                }                        }            Else{MessageBox.Show ("Input method is not selected, please select! "); }        }        /// <summary>        ///Open the Handwriting Board of Sogou Input Method/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidBtnopenhand_click (Objectsender, EventArgs e) {            Try            {                //get the value of the tablet button                stringHandtext = This. Btnopenhand.text; if(Handtext = ="Open Handwriting Pad")                {                    //Start a handwriting programSystem.Diagnostics.Process.Start (@"C:\Program Files (x86) \sogouinput\components\handinput\1.1.0.282\handinput.exe");                }            }            Catch(Exception) {MessageBox.Show ("not installed Sogou input method of the tablet, can't open!"); return; }        }        /// <summary>        ///Open Sogou IME program/// </summary>        /// <param name= "Sender" ></param>        /// <param name= "E" ></param>        Private voidBtnopeninput_click (Objectsender, EventArgs e) {            Try            {                //gets the value of the Input Method button                stringInputtext = This. Btnopeninput.text; if(Inputtext = ="Open Input Method")                {                    //start the Input Method toolSystem.Diagnostics.Process.Start (@"C:\Program Files (x86) \sogouinput\8.4.0.1039\sgtool.exe"); }            }            Catch(Exception) {MessageBox.Show ("did not find a specific version of Sogou input method, unable to open!"); return; }        }    }}

3. Interface Demo

1) Get all input methods for native installation

2) Set default IME to output language (check Input method)

After setting the input method, display the effect

3. Open Tablet function

Click the button to open the Sogou IME program

4. Open IME Toolbar

This situation is the Input Method toolbar cannot be found, you can open it through this

When you click the button, open the IME toolbar

How to get the native installation input method in C # Winform, and set it as the default output language, how to open Sogou ime and tablet

Related Article

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.