更改“区域和语言”设置操作系统编程 [英] Changing the 'Region and Language' OS setting programmatically

查看:1389
本文介绍了更改“区域和语言”设置操作系统编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够改变的区域和语言的的操作系统(Windows 7)从C#程序的设置。我不反对执行命令行命令,但我只是尽量得到的发现如何推出的区域和语言的对话框:控制/名称Microsoft.RegionAndLanguage



这是一个语言本地化问题,在控制就像的DateTimePicker 只能使用Windows的区域和语言的设置(见这里的详细信息);然而,更新操作系统,以符合应用程序的语言设置超出这一点,最终是所期望的目标。



建议和/或变通方法,将不胜感激。


解决方案

我成功地实现了唯一的解决办法是修改注册表。在Windows 7中,当语言发生了变化,新的条目添加到在子项的注册表: HKEY_CURRENT_USER\Control Panel\Desktop 。该密钥将包含类型的条目 PreferredUILanguages​​Pending REG_MULTI_SZ ,其价值将决定用户界面语言。对于更改应用于当前用户需要注销并重新登录。这可以用下面的代码来完成:



<预类=郎-CS prettyprint-覆盖> 的RegistryKey键= Registry.CurrentUser.OpenSubKey(@ 控制Panel\Desktop,真正的);
的String [] LANG = {EN-ZA};
key.SetValue(PreferredUILanguages​​Pending,郎咸平,RegistryValueKind.MultiString);



语言包需要之前它可以被设置为安装。对于语言包的列表查看。这里或的此处。当1个多语言包安装选项更改UI语言将出现在控制面板>区域和语言>键盘和语言>显示语言


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

This is a language localisation problem where Controls 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.

解决方案

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_USER\Control Panel\Desktop. 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 Panel\Desktop", true);
string[] lang = {"en-ZA"};
key.SetValue("PreferredUILanguagesPending", lang, RegistryValueKind.MultiString);

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.

这篇关于更改“区域和语言”设置操作系统编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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