Using a different language in a text box in c # winform

I know this topic is being discussed here and on other blogs, but none of the methods could help me.

I want to enter the Malayalam language in the text box. I have done it so far. I installed the font "AnjaliOldLipi". I can print Malayalam in Notepad. But I can not do the same in a Winform application. In the text box, it is displayed as English.

I tried the following code with no result.

private void richTextBox_test_Leave(object sender, EventArgs e) { System.Globalization.CultureInfo TypeOfLanguage = new System.Globalization.CultureInfo("en-us"); InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage); } private void richTextBox_test_Enter(object sender, EventArgs e) { MessageBox.Show("textbox ebntereed"); System.Globalization.CultureInfo TypeOfLanguage = new System.Globalization.CultureInfo("ms-MY"); InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(TypeOfLanguage); richTextBox_test.Font = new Font("AnjaliOldLipi", 12); } 

Then I tried the following code. Now the keyboard changes by default (I see it on the taskbar) when I enter the text box. However, when typing, the text appears in English. I need to press "Ctrl + Shift" to write to "malayalam". I don’t know why, but I need to write in Malayalam without pressing any keyboard buttons.

+4
source share
4 answers

For input to Malayalam, there are ready-made keyboards available for free. I used the keyboard "Malayalam Signpost 2". It worked perfect for me. I also heard that the other Varamoji keyboard has many possibilities. Some other points: when saving to the database, you need to save this malayalam as unicode. The SQL query for it is as follows:

  "Insert into table_1 values (N'"+textBox1.Text+"')"; 

The answer to my question lies below:

  private void textBox1_Enter(object sender, EventArgs e) { SetKeyboardLayout(GetInputLanguageByName("mal")); } 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; } public void SetKeyboardLayout(InputLanguage layout) { InputLanguage.CurrentInputLanguage = layout; } 
0
source

Simplicity is all in a successful program, there is no need for complexity, save your efforts for more demanding things and try the following:

 using System; using System.Windows.Forms; using System.Globalization; namespace TestingTextBoxAutoLangSwitch { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // Switching to Arabic Jordan private void textBox2_Enter_1(object sender, EventArgs e) { Application.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("ar-jo")); } // Switching back to English USA private void textBox2_Leave(object sender, EventArgs e) { Application.CurrentInputLanguage = InputLanguage.FromCulture(new CultureInfo("en-us")); } } } 
+1
source

.NET applications are unicode. Go to the control panel, regional and language settings and change the default input language to Malay. Your application should follow. (This assumes that input storage is also Unicode).

If you want to do it on the fly:

  System.Globalization.CultureInfo maylay = new System.Globalization.CultureInfo("ms"); System.Threading.Thread.CurrentThread.CurrentCulture = malay; 
0
source

I use these codes: First of all, you must find the name of the culture language that you want. getInutLanguageByName method will return the language you requested Then you will make sure that you have installed the required language or not, if so, return the requested language. Then it is very easy to change the input language ...

 private static InputLanguage GetInutLanguageByName(string layOut) { foreach (InputLanguage lng in InputLanguage.InstalledInputLanguages) { if (lng.Culture.DisplayName == layOut) { return lng; } } return null; } private void SetKeyboardLayout(InputLanguage Layout) { InputLanguage.CurrentInputLanguage = Layout; } private void FirstNameTextBox_Enter(object sender, EventArgs e) { SetKeyboardLayout(GetInutLanguageByName("Persian")); } 
0
source

Source: https://habr.com/ru/post/1495202/


All Articles