【问题标题】:How to get the selected language in C# when more than one culture is installed?安装多种文化时如何在 C# 中获取所选语言?
【发布时间】:2016-07-20 19:50:31
【问题描述】:

Windows 上似乎安装了两种文化(语言)。例如 en-us(英语)和中文,我们可以通过 Alt+Shift 更改语言,如您所知。我需要显示所选语言。例如,如果当我单击 Windows 窗体上的按钮时选择了中文,则会选择一个按摩框告诉我中文。像这样:

if(culture == "en_us")
{
    messagebox.show("English");
}
else
{
    messageBox.show("Chinese");*
}

【问题讨论】:

  • @gravity 这只会显示额外安装的语言,而不是选择的当前语言。
  • CultureInfo.CurrentCulture? InstalledUICulture 应该是列表,本身......不是相反吗?同样的问题还有另一个答案,详细说明了如何更改该特定线程的文化:System.Globalization.CultureInfo.DefaultThreadCurrentCulture=CultureInfo.InstalledUICulture;

标签: c# cultureinfo culture


【解决方案1】:

使用 CultureInfo 对象来表示当前线程使用的区域性。

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

希望对你有帮助。

【讨论】:

    【解决方案2】:

    您可能需要查看 get the current selected language of the language bar in windows 7 和现代 WinAPI 文档。

    在这个文档https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.keyboardlayoutid(v=vs.110).aspx

    如果我对您的理解正确,它将帮助您实现目标(KeyboardLayoutId 可能会引导您到达那里,抱歉,我现在无法测试它)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 2016-12-04
      • 2014-04-03
      相关资源
      最近更新 更多