如何在WinForm应用程序中遵守/继承用户的语言设置? [英] How to honor/inherit user's language settings in WinForm app?

查看:123
本文介绍了如何在WinForm应用程序中遵守/继承用户的语言设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我过去曾使用全球化设置,但没有在.NET环境中使用全球化设置,这是此问题的主题.我所看到的肯定是由于我尚未学习的知识,所以我很欣赏以下内容.


设置: 我的默认语言设置是英语(特别是en-us).我在开发系统(WinXP)上添加了第二种语言(丹麦语),然后打开了语言栏,因此我可以随意选择其中一种.


我在语言栏上选择了丹麦语,然后打开了记事本,并在语言栏上找到了恢复为英语的语言.我知道语言设置是每个应用程序,因此记事本似乎将默认设置重新设置为英语. (我发现自Windows以来,因此在世界范围内使用了记事本,这很奇怪.)关闭记事本会将语言栏上的设置返回到丹麦语.然后,我启动了打开的自定义WinForm应用程序-我知道它没有设置语言-并且 在打开时也从英语还原为丹麦语,然后在终止时又回到丹麦语!

问题#1A::如何在启动时获取WinForm应用程序以继承语言栏的当前设置?我的实验似乎表明,每个应用程序均以系统默认值开头,并且要求用户在应用程序运行后对其进行手动更改-对于任何想使用多种语言的人来说,这似乎是一个很大的不便!

问题#1B:实际上,如果必须在多语言场景中手动设置语言,则如何更改默认系统语言(例如,丹麦语),以便测试我的语言应用程序以另一种语言启动?


我为下一个实验在应用程序中添加了当前语言的显示.具体来说,我在标签上设置了MouseEnter处理程序,将其工具提示设置为CultureInfo.CurrentCulture.Name,因此,每次将鼠标悬停在上方时,我都应该看到当前的语言设置.由于在启动应用程序之前设置语言无效,因此我先启动了它,然后将语言设置为丹麦语.我发现某些事情(例如在TextBox中键入内容)确实符合此丹麦语设置.但是,将鼠标悬停在标记的标签上仍会显示en-us!

问题#2A:为什么CultureInfo.CurrentCulture.Name不能从我的语言栏中反映出更改,而我的应用程序的其他部分似乎可以识别出更改? (尝试CultureInfo.CurrentUICulture.Name产生了相同的结果.)

问题#2B::是否有事件触发语言栏上的更改,以便在语言设置更改时在我的应用程序中识别出来?


2010.05.13更新

Microsoft的Eric提供的简短但有趣的信息(请参阅下面的答案)仅直接解决了我的四个问题之一(#2A),但这只是我进一步研究并找出其余问题所需的动力.为了使其他可能对此感到迷惑的人受益,这是我发现的东西:

答案#1A::应用程序继承了默认输入语言的设置,而不是您在语言栏上指定的语言.应用程序运行后,您的应用程序会立即注意到语言栏 上的更改.

答案#1B:通过区域和语言选项"控制面板>>语言选项卡>>详细信息>>设置选项卡>>默认输入语言,可以设置默认输入语言.

答案2A:埃里克(Eric)回答说,当前的文化与语言栏上反映的当前输入语言有所不同.在文本框中键入内容仅受当前输入语言的影响.

答案2B::没有针对输入语言或当前区域性更改通知的预定义事件.这里要注意的一个重要事实是输入语言的更改会立即自动识别,而当前的区域性更改则不会自动识别.您必须重新启动应用程序才能使当前的区域性更改生效-除非您可以注意到更改并亲自采取行动.为此,我找到了MSDN文章( CultureInfo类的许多面孔)提供了这样的钩子来注意到更改.

解决方案

正在使用三种独立的语言设置.语言栏控制输入语言( InputLanguage )与显示UI(CurrentUICulture)的语言不同,而与显示/格式化/解析(CurrentCulture)的语言不同.

这确实令人困惑.

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.

解决方案

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.

这篇关于如何在WinForm应用程序中遵守/继承用户的语言设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆