winform textbox光标进入时,自动切换到五笔输入法

        private void txtSearch_Enter(object sender, EventArgs e)
        {
            txtSearch.ImeMode = System.Windows.Forms.ImeMode.On;
            //InputLanguage.CurrentInputLanguage=InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("zh-CN"));

            string[] languagename = new string[] { "五笔", "拼音", "中文" };
            bool bResult = false;
            for (int i = 0; i < languagename.Length; i++)
            {
                foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
                {
                    if (lang.LayoutName.IndexOf(languagename[i]) >= 0)
                    {
                        InputLanguage.CurrentInputLanguage = lang;
                        bResult = true;
                        break;
                    }
                }

                if (bResult)
                    break;
            }
        }

首先是将 textbox的 imeMode设置为 on (全角模式:中文输入)

然后从已安装的输入法中遍历 几个指定的输入法,如果能够成功匹配到就优先使用之

 

效果图:


 

你可能感兴趣的:(object,String,输入法,WinForm,textbox)