To change the keyboard layout to a different culture in C#, you can use the "InputLanguage" class, which is part of the System.Windows.Forms namespace.
Here is an example of how you can change the keyboard layout to French (France):
private void SetKeyBoardToArabic()
{
InputLanguage newLanguage = InputLanguage.FromCulture(new System.Globalization.CultureInfo("ar-SA"));
InputLanguage.CurrentInputLanguage = newLanguage;
}
There is an other alternative as well to acheive this functionality through SendKeys class. There is a Send method which is use for keystrokes to the active application. on Keyboard we used ALT+SHIFT to toggle language. you can send ALT+SHIFT in textBox1 Enter and Leave event. like:
private void textBox1_Enter(object sender, EventArgs e)
{
SendKeys.Send("%(+)");
}
private void textBox1_Leave(object sender, EventArgs e)
{
SendKeys.Send("%(+)");
}
Where % is using for ALT and + is for SHIFT. Read more regarding SendKeys code through below link:
SendKeys.Send(String) Method (System.Windows.Forms) | Microsoft Learn[
^]