Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to shift the keyboard to Arabic by program. I have done this program in older studio version but could not do that in community studio version. all references and property were same.
I added textBox1 to the Form1 design and expect the cursor should change its shape immediately but that did not happened
the program build successfully


What I have tried:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using System.Globalization;
using System.Threading;
      private void FormLoad(object sender, EventArgs e)
        {
            SetKeyBoardToArabic();
        }
        private void SetKeyBoardToArabic()
        {

            //http://www.microsoft.com/middleeast/msdn/WinFormsAndArabic.aspx#_Toc136842137
            //put keyboard on arabic
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(Application.CurrentCulture);//Set language to current culture
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("ar-SA"));// now Shift keyboard to Arabic saudia arabia

        }
Posted
Updated 25-Jan-23 8:51am
v3

1 solution

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):

C#
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:
C#
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[^]
 
Share this answer
 
Comments
Engineer khalid 27-Jan-23 1:40am    
the 1st solution did not worked but the other works fine
Engineer khalid 27-Jan-23 1:44am    
i gave you 5 star grade but i can see only the 1st left star and part of the second one activated
M Imran Ansari 28-Jan-23 13:52pm    
Happy to hear second solution works for you and that's the grade/star. Cheers :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900