I have a Winforms application in c# and I want a TextBox to change language automatically when it gets focused.

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 textBox, the language does not change. What can I do?

Edit
Report