6

I'm reviewing some code for a form, and see the following :

void SomeTextBox_Enter(object sender, EventArgs e)
{
    InputLanguage.CurrentInputLanguage = GetLocalLanguage(DataModel.Country);
    SomeTextBox.ImeMode = ImeMode.On;
}

where GetLocalLanguage() goes through InputLanguage.InstalledInputLanguages and returns the country-specific one if applicable.

What is the purpose of this code? Why would we want to change the Input Language?

Rachel
  • 130,264
  • 66
  • 304
  • 490
  • I think mostly in multithreading environment to ensure that the current thread has the correct InputLanguage. `Gets or sets the input language for the current thread.` – Jehof Nov 04 '15 at 18:26
  • From [MSDN](https://msdn.microsoft.com/en-us/library/system.windows.forms.inputlanguage(v=vs.110).aspx) "An input language is a culture/keyboard layout pair that determines how the physical keys on a keyboard map or plot to characters in a language. The input language is based on a Windows input locale identifier, such as that returned by the Platform SDK function, GetKeyboardLayout. The input locale identifier is also called a handle to a keyboard layout (HKL) value." -- So it might be for supporting different keyboard layouts / languages. – sab669 Nov 04 '15 at 18:39
  • (cont.) Does the application "expect" to be primarily used by 1 particular region? I'm not sure if the different InputLanguages might translate key codes differently. So that could tie into that, perhaps. – sab669 Nov 04 '15 at 18:40
  • @sab669 We have different tabs for different countries/regions, and some tabs have this code setup on the Enter event of one of the TextBoxes. I am confused what this code is supposed to do... there is no multithreading in use here. I've updated my question with a sample block of code. – Rachel Nov 04 '15 at 18:51
  • Tabs for different regions in the sense of "If it's a Customer from X country, fill out this tab" or "Someone in X country will use this tab for this record, then someone in Y country will open this record and fill out Y tab"? If the latter, then it might make sense to ensure the application is expecting the correct `InputLanguage` as different people from different regions modify it. Even for the former it might make sense, if the person entering the data is going to be entering characters from various languages. – sab669 Nov 04 '15 at 18:53
  • @sab669 Users can be from all over the world, and can fill out the data on any number of the region-specific tabs. So it sounds like this is meant to be a way to handle non-english character input from different regions/keyboards? For example, the tab for China changes the InputLanguage so it can handle chinese character input that may not be handled correctly with the standard English language input? – Rachel Nov 04 '15 at 19:04
  • That's what it sounds like to me. I couldn't find any concrete, real-world explanations for using / setting the `InputLanguage` on google though; just lots of questions about how to do it. Seems like you could try manually setting the `InputLanguage` to one value, enter a key and see what it's interpreted as, then change the language again and press the same key and see if it's a different value. Like using the `qwerty` layout versus `dvorak`, the same physical key on the keyboard might send a different key code to the software. Or be interpreted differently. – sab669 Nov 04 '15 at 19:05
  • Thanks @sab669, if I get some time I'll do some tests like that and add the results here. I tried doing the same google searches and was getting the same results :) – Rachel Nov 04 '15 at 19:24
  • No problem! Glad to help a former co-worker ;) – sab669 Nov 04 '15 at 19:31
  • 1
    @sab669 lol is that you Doug? I thought the username looked familiar.... I'm not at home (in NC for a few weeks) or I'd get on steam and chat :) – Rachel Nov 04 '15 at 19:38
  • 3
    One of the uses is mentioned here - http://blogs.msdn.com/b/vsarabic/archive/2007/04/29/changing-the-input-language-in-a-textbox-at-runtime.aspx . So perhaps in your case it automatically switches the keyboard as per the country – Kapoor Nov 04 '15 at 20:05
  • Thanks @Kapoor, the code there actually looks very similar to the code I'm looking at, so I'm guessing it originated based on that blog post :) – Rachel Nov 04 '15 at 20:32
  • Here is an example of usage [How to change input-language in a windows forms application for a specific control?](https://stackoverflow.com/questions/35813818/how-to-change-input-language-in-a-windows-forms-application-for-a-specific-contr) - The OP wants to change input language automatically for some controls. Suppose you have a form which you need to enter data into some fields and some of them need English data and some of them need Persian data. Based on the code which I posted for that question, I created an Extender control which allow language be set at design-time. – Reza Aghaei Aug 06 '16 at 11:07

1 Answers1

0

The input language element is simply the container for all the input language data. There is a sub item called "CurrentInputLanguage" which can be set and overridden from the Form's own language (defined in the resources).

In all my tests I have come to the conclusion that all changes are ignored.

  • The keyboard input does not change. The keys are still identical.
  • The formatting does not change. Numbers and parsed values do not change format.

I assume that this value should have been readonly.

Joe Sonderegger
  • 784
  • 5
  • 15
  • This is not true. I must say. See this answer: http://stackoverflow.com/a/23594038/6201755 You must have some other issues. Can you please edit your post so it is clear that it was your special case? – ib11 May 19 '16 at 05:39