问题描述
我希望能够从 C# 程序更改操作系统 (Windows 7) 的区域和语言 设置.我并不反对执行命令行命令,但我只知道如何启动 Region and Language 对话框:control/name Microsoft.RegionAndLanguage
I'd like to be able to change the Region and Language settings of the operating system (Windows 7) from a C# program. I'm not against executing command-line commands but I've only gotten as far as discovering how to launch the Region and Language dialog: control /name Microsoft.RegionAndLanguage
这是一个语言本地化问题,其中 Control
像 DateTimePicker
只能使用 Windows Region and Language 设置(请参阅此处的 详情);然而,更新操作系统以符合应用程序的语言设置超出了此范围,最终成为预期目标.
This is a language localisation problem where Control
s like DateTimePicker
can only use the Windows Region and Language settings (see here for details); however updating the operating system to conform to the application's language settings extends beyond this and is ultimately the desired goal.
我们将不胜感激建议和/或解决方法.
Suggestions and/or workarounds would be appreciated.
推荐答案
我设法实现的唯一解决方案是修改注册表.在 Windows 7 中,更改语言时,会在注册表的子项中添加一个新条目:HKEY_CURRENT_USERControl PanelDesktop
.此键将包含 REG_MULTI_SZ
类型的条目 PreferredUILanguagesPending
,其值将确定 UI 语言.要应用更改,当前用户需要注销并再次登录.这可以使用以下代码完成:
The only solution I managed to implement was to modify the registry. In Windows 7, when the language is changed, a new entry is added to the Registry in the subkey: HKEY_CURRENT_USERControl PanelDesktop
. This key will contain the entry PreferredUILanguagesPending
of type REG_MULTI_SZ
and its value will determine the UI language. For the change to be applied the current user needs to log off and log in again. This can be done using the following code:
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control PanelDesktop", true);
string[] lang = {"en-ZA"};
key.SetValue("PreferredUILanguagesPending", lang, RegistryValueKind.MultiString);
语言包需要安装才能设置.如需语言包列表,请查看此处或这里.当安装超过 1 个语言包时,更改 UI 语言的选项将出现在 Control Panel >地区和语言 >键盘和语言 >显示语言
.
The language pack needs to be installed before it can be set. For a list of language packs check here or here. When more than 1 language pack is installed option to change the UI language will appear in Control Panel > Region and Language > Keyboards and Languages > Display language
.
这篇关于以编程方式更改“区域和语言"操作系统设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!