Click here to Skip to main content
15,884,472 members
Articles / Programming Languages / C# 3.5
Tip/Trick

TextBox Accepting Regional Language Input (Malayalam)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
20 Jun 2014CPOL1 min read 15.3K   7   2
Making a TextBox accept Regional Language Input (Malayalam)

Introduction

My attempt here is to give a tip to one of the most asked questions by beginners, "How to make language XXXXX as the input type to a Windows Form control?"

Background

I was developing a Windows Form application where the user input is in my mother tongue "Malayalam", but the issue is the user is not aware of Malayalam keyboard, so he wants a Google Transliteration type input... means the user will type the Malayalam words in English but the system will convert it to the Malayalam format. So I cannot simply set a font to the textbox. I downloaded and installed the Microsoft indic tool for malyalam.

Using the Code

Step 1: First create a Windows Form application with a textbox control in it.

Step 2: The Inputlanguage of the textbox must be Malayalam when the user starts typing and must change back to English when the user input is over. So create two events for Enter and Leave.

C++
private void textBox2_Enter(object sender, EventArgs e)
{
           
}
private void textBox2_Leave(object sender, EventArgs e)
{
           
}

Step 3: Then, create a function to get the installed language:

C++
public static InputLanguage GetInputLanguageByName(string inputName)
{
    foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
    {
        if (lang.Culture.EnglishName.ToLower().StartsWith(inputName))
            return lang;
    }
    return null;
}

This function will get all the Inputlanguage which has the Name starting with the parameters given to the function.

Step 4: Create a function to set the keyboadlayout to the input language selected.

C++
public void SetKeyboardLayout(InputLanguage layout)
{
    InputLanguage.CurrentInputLanguage = layout;
} 

Step 5: Finally, call the function inside the Enter and Leave event of the Textbox.

C++
private void textBox2_Enter(object sender, EventArgs e) 
{
    SetKeyboardLayout(GetInputLanguageByName("mal"));
}
private void textBox2_Leave(object sender, EventArgs e)
{
    SetKeyboardLayout(GetInputLanguageByName("eng"));
}

Points of Interest

Here, I had used only one textbox control, we can use this in any Winform controls and also many other keyboards are available for free download over the web. So keeping this as a class and passing controls and the inputlanguagename as parameter will help in reducing code irrespective of control and language.

License

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


Written By
Software Developer
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
deshjibon15-Jul-14 9:36
deshjibon15-Jul-14 9:36 
GeneralMy vote of 5 Pin
ishihidul14-Jul-14 14:57
ishihidul14-Jul-14 14:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.