How to honor/inherit user's language settings in WinForm app?

孤街醉人 提交于 2020-02-04 05:41:44

问题


I have worked with globalization settings in the past but not within the .NET environment, which is the topic of this question. What I am seeing is most certainly due to knowledge I have yet to learn so I would appreciate illumination on the following.


Setup: My default language setting is English (en-us specifically). I added a second language (Danish) on my development system (WinXP) and then opened the language bar so I could select either at will.


I selected Danish on the language bar then opened Notepad and found the language reverted to English on the language bar. I understand that the language setting is per application, so it seemed that Notepad set the default back to English. (I found that strange since Windows and thus Notepad is used all over the world.) Closing Notepad returned the setting on the language bar to Danish. I then launched my open custom WinForm application--which I know does not set the language--and it also reverted from English to Danish when opened, then back to Danish when terminated!

Question #1A: How do I get my WinForm application upon launch to inherit the current setting of the language bar? My experiment seems to indicate that each application starts with the system default and requires the user to manually change it once the app is running--this would seem to be a major inconvenience for anyone that wants to work with more than one language!

Question #1B: If one must, in fact, set the language manually in a multi-language scenario, how do I change my default system language (e.g. to Danish) so I can test my app's launch in another language?


I added a display of the current language in my application for this next experiment. Specifically I set a MouseEnter handler on a label that set its tooltip to CultureInfo.CurrentCulture.Name so each time I mouse over I thought I should see the current language setting. Since setting the language before I launch my app did not work, I launched it then set the language to Danish. I found that some things (like typing in a TextBox) did honor this Danish setting. But mousing over the instrumented label still showed en-us!

Question #2A: Why does CultureInfo.CurrentCulture.Name not reflect the change from my language bar while other parts of my app seem to recognize the change? (Trying CultureInfo.CurrentUICulture.Name produced the same result.)

Question #2B: Is there an event that fires upon changes on the language bar so I could recognize within my app when the language setting changes?


2010.05.13 Update

The short but sweet information provided by Eric from Microsoft (see his answer below) directly addressed only one of my four questions (#2A) but it provided just the impetus I needed to delve further and figure out the rest. For the benefit of others who may also be befuddled by this, here is what I uncovered:

Answer #1A: An application inherits the setting of the default input language, not the language you specify on the language bar. Once your application is running, then changes on the language bar will be noticed immediately by your app.

Answer #1B: Setting the default input language is done via Regional and Language Options control panel >> Languages tab >> Details >> Settings tab >> default input language.

Answer #2A: Answered by Eric, the current culture is distinct from the current input language that is reflected on the language bar; typing in a text box is influenced only by the current input language.

Answer #2B: There is no predefined event for either input language or current culture change notification. An important fact to note here is that input language changes are automatically recognized immediately while current culture changes are not. You must restart your application for a current culture change to take effect--unless you can notice the change and act upon it yourself. To that end I found an MSDN article (The Many Faces of the CultureInfo Class) that provides just such a hook to notice the change.


回答1:


There are three separate language settings at play. The language bar controls the input language (InputLanguage) which is distinct from the language for displaying UI (CurrentUICulture) which is distinct from the language for sorting/formatting/parsing (CurrentCulture).

It is true that this is confusing.



来源:https://stackoverflow.com/questions/2820843/how-to-honor-inherit-users-language-settings-in-winform-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!