多个文本框,都实现全选;光标进入就自动切换到五笔输入法

step1:

        private void txt_Enter(object sender, EventArgs e)
        {
            ((TextBox)sender).ImeMode = System.Windows.Forms.ImeMode.On;

            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;
            }
        }
 
        public void txt_KeyPress(object sender,KeyPressEventArgs e)
        {
            if (e.KeyChar == 1)
            {
                ((TextBox)sender).SelectAll();
            }
        }

step2:在form_load中添加

            txtSentence.Enter += new EventHandler(txt_Enter); // 光标进来时自动切换到五笔输入法
            txtRemark.Enter += new EventHandler(txt_Enter);

            txtSentence.KeyPress+=new KeyPressEventHandler(txt_KeyPress); // Ctrl + A 全选
            txtRemark.KeyPress += new KeyPressEventHandler(txt_KeyPress);  


 


 

你可能感兴趣的:(多个文本框,都实现全选;光标进入就自动切换到五笔输入法)