切换输入法

Posted on 2019-01-24 13:56  努力成长静待花开  阅读(286)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  InputLanguage类的CurrentInputLanguage

  public static InputLanguage CurrentInputLanguage { get; set;};

  IstalledInputLanguage属性

  public static  InputLanguageCollecation InstalledInputlanguage {get ;};

实现代码:

        private void Form1_Load(object sender, EventArgs e)
        {                                                               //获取系统中安装的文字输入法
            InputLanguageCollection ILcollection = InputLanguage.InstalledInputLanguages;
            foreach (InputLanguage input in ILcollection)
                comboBox1.Items.Add(input.LayoutName);
            InputLanguage Cinput = InputLanguage.CurrentInputLanguage;  //获取当前输入法
            textBox1.Text = Cinput.LayoutName;
            InputLanguage Dinput = InputLanguage.DefaultInputLanguage;  //获取默认输入法信息
            textBox2.Text = Dinput.LayoutName;
            textBox3.Text = Cinput.Culture.DisplayName;                 //获取输入法的语言区域 
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            InputLanguage SetInput=InputLanguage.InstalledInputLanguages[comboBox1.SelectedIndex];
            InputLanguage.CurrentInputLanguage = SetInput;                      //设置当前输入法
            InputLanguage Cinput = InputLanguage.CurrentInputLanguage;
            textBox1.Text = Cinput.LayoutName;
            InputLanguage Dinput = InputLanguage.DefaultInputLanguage;
            textBox2.Text = Dinput.LayoutName;
            textBox3.Text = Cinput.Culture.DisplayName;
        }