I know that this is a much discussed topic here and in other blogs but none of the techniques could help me out.
I want to type in Malayalam Language in a text box. I did this so far. I have installed a font 'AnjaliOldLipi'. I can type in Malayalam in Notepad. But I can't do the same in Winform application. It appears as English in textbox.
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 default keyboard is changing(I can see it on my task bar) when I enter the text box. Still when typing, the text is appearing in English. I need to press 'Ctrl+Shift' to write in 'malayalam'. I don't know why but I need to write in 'malayalam' without pressing any keyboard buttons.
Simplicity is everything in successful program, no need for complexity, save your effort for more demanding things, and try this:
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"));
}
}
}
I use these codes: First of all you must find the name of the culture language you want. method "GetInutLanguageByName" will return the language that you requested Then you will check whether you installed the requested language or not, if yes then return the requested language. Then change the input language very easy...
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"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With