How to change the language of a TextBox automatically

Try this ..

private void textBox1_Enter(object sender, EventArgs e)
{
    SetKeyboardLayout("FA");
}


private void SetKeyboardLayout(InputLanguage layout)
{
foreach (InputLanguage Lng in InputLanguage.InstalledInputLanguages)
{
    if (Lng.Culture.EnglishName.ToUpper().StartsWith(layout.ToString()))
    {
        InputLanguage.CurrentInputLanguage = Lng;
    }

} 

}

Things to check:

  1. Is "fa" an installed language?
  2. Have you attached textBox1_Enter and textBox1_Leave to events dispatched by textBox1?
  3. Have you run it via the debugger and checked GetInputLanguageByName is called and that the correct language is called when focus is gained and lost?

Tags:

C#

Winforms