I have a Winforms application in C # and I want the TextBox to automatically change the language when it focuses.
I tried this code:
private void textBox1_Enter(object sender, EventArgs e) { SetKeyboardLayout(GetInputLanguageByName("fa")); } private void textBox1_Leave(object sender, EventArgs e) { SetKeyboardLayout(GetInputLanguageByName("eng")); } public static InputLanguage GetInputLanguageByName(string inputName) { foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) { if (lang.Culture.EnglishName.ToLower().StartsWith(inputName)) { return lang; } } return null; } private void SetKeyboardLayout(InputLanguage layout) { InputLanguage.CurrentInputLanguage = layout; }
But when I enter the text box, the language does not change. What can I do?
amirhossein
source share