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 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.
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 entryPreferredUILanguagesPending
of typeREG_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: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
.NUTS. Seriously. Think about what you do here; I start your program and you reconfigure my whole computer to make a small UI element work? Preferably without asking or telling me?
There are laws against that - this can be seen as unauthorized manipulation of a computer.
Use a proper control and properly program; but do not commit sabotage on that level.
Sounds to me as if changing the Culture/UICulture of your application should be sufficient
e.g.
I found a solution here: https://support.microsoft.com/de-de/help/2764405/how-to-automate-regional-and-language-settings-in-windows-vista-window
You need to create an XML file with the following content:
Then run this command:
This would set the format to
English (United States)
for the currently logged in user.Although the article is about Windows Vista, this also works in Windows 7.
I think, you are thinking in opposite to what you need. Often application(s) may need to help/honor/satisfy user OS settings than changing them for app's convenience. Have a look at the post with problem similar to your's : How can I change a Windows user's regional settings/date format?
I've found a good replacement for the
DateTimePicker
: http://www.visualhint.com/fieldpackeditorYou will have the same problems with all the system controls and system dialogs like
OpenFileDialog
,PrintDialog
, etc., they are not localizable in .NET.But thinking about it, why would you want to change the culture for your application? The user can change his region and language settings by himself using the control panel, why should your application overwrite those settings?