7

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.

Pooven
  • 1,744
  • 1
  • 25
  • 44
  • I think you shouldn't change the system's language settings. The best you can do is create a new, localizable, `DateTimePicker` control, or search for a ready-made one. – vulkanino Mar 02 '12 at 09:02
  • Just a guess, won't setting up a custom format for the Date picker control solve your purpose ? – V4Vendetta Mar 02 '12 at 09:10
  • @V4Vendetta no, the custom format is not enough, he might want to change other settings, like the first day of the week, etc. – vulkanino Mar 02 '12 at 09:15
  • The software I'm developing effectively replaces the desktop; changing the language within the software should seamlessly update the OS - which is only accessible from within the software. So in this case it's ideal that the OS conforms. I've also consider using alternatives to the `DateTimePicker` (which is a bit undesirable) but while responding I realize that changing the OS language would be important. I'll update my original post accordingly. – Pooven Mar 02 '12 at 09:30

6 Answers6

4

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.

Pooven
  • 1,744
  • 1
  • 25
  • 44
3

Sounds to me as if changing the Culture/UICulture of your application should be sufficient

e.g.

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
Dominik
  • 3,342
  • 1
  • 17
  • 24
  • 1
    don't think so, in the provided link Microsoft says: _This behavior occurs because the DateTimePicker control and the MonthCalendar control are Microsoft Windows common controls. Therefore, the operating system's user locale determines the user interface of these controls._ – vulkanino Mar 02 '12 at 09:04
  • I stand corrected and agree with your comment to the OPS question, build a new control – Dominik Mar 02 '12 at 09:08
1

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:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
    <gs:UserList>
        <gs:User UserID="Current"/>
    </gs:UserList>
    <gs:UserLocale>
        <gs:Locale Name="en-US" SetAsCurrent="true"/>
    </gs:UserLocale>
</gs:GlobalizationServices>

Then run this command:

control intl.cpl,, /f:"<path to XML file>"

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.

Torben Kohlmeier
  • 6,713
  • 1
  • 15
  • 15
1

I've found a good replacement for the DateTimePicker: http://www.visualhint.com/fieldpackeditor

You 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?

vulkanino
  • 9,074
  • 7
  • 44
  • 71
  • We only use the `DateTimePicker` in a single form; I don't think our company would approve of purchasing new software to achieve this goal. However, I have realized that my goal extends beyond `DateTimePicker`. Thank you for your reply. – Pooven Mar 02 '12 at 09:39
0

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?

Community
  • 1
  • 1
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22
  • Thank you for your reply. I had also found a similar post [here](http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/93ba702d-b92c-43f2-adf9-1c8c3d4c2e4e/). It seems that modifying the registry is the only possibility. – Pooven Mar 02 '12 at 09:37
0

This is a language localisation problem where Controls like DateTimePicker can only use the Windows >Region and Language settings

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.

Pooven
  • 1,744
  • 1
  • 25
  • 44
TomTom
  • 61,059
  • 10
  • 88
  • 148
  • I'm sorry you feel so strongly about this. I have updated my post to provide a better context: ultimately this behaviour would be the expected result from the end user. – Pooven Mar 02 '12 at 09:40
  • Agree. That said iyou ahve a veryu nusual piece of software, so ... bear with me tha this was not obvious. – TomTom Mar 02 '12 at 10:32
  • I understand; I hadn't defined my situation well enough to ask for advice. We live and we learn :) – Pooven Mar 02 '12 at 15:43
  • 2
    This was an extremely unhelpful response. While the original question may have been poorly framed, the general issue of automated changes to Windows regional settings is still of interest and deserves an appropriate (if qualified) response. It's fair to observe that doing this in an unwanted way would be upsetting to a user, however, it's perfectly reasonable to develop date handling utilities. In my case, I would like to change settings to enable automated testing under different (genuine) culture settings - an answer here would still serve me. – user1164178 Sep 01 '14 at 01:29