Dynamically updating the CultureInfo
-
Hi, I can translate my application using the procedure described in the MSDN article 'Walkthrough: Localizing Windows Forms'. In that article, one one language is set, by instantiating a CultureInfo() in the constructor of the from and setting it on the current thread's CurrentUICulture. But now, how do I dynamically (at run time) change the language that the UI is show in? I've tried calling InitializeComponent() after setting Thread.CurrentThread.CurrentUICulture but that doesn't work. I know I can have the user close the application and restart it so that I can set the correct CultureInfo() at the start of the program, but is there another way? Thanks. cheers, roel
-
Hi, I can translate my application using the procedure described in the MSDN article 'Walkthrough: Localizing Windows Forms'. In that article, one one language is set, by instantiating a CultureInfo() in the constructor of the from and setting it on the current thread's CurrentUICulture. But now, how do I dynamically (at run time) change the language that the UI is show in? I've tried calling InitializeComponent() after setting Thread.CurrentThread.CurrentUICulture but that doesn't work. I know I can have the user close the application and restart it so that I can set the correct CultureInfo() at the start of the program, but is there another way? Thanks. cheers, roel
-
You can set the currentculture property of the thread your in.
Thread.CurrentThread.CurrentCulture = New CultureInfo("nl-NL", False)
-
Hi, Thanks, but that only works when doing it before the UI is created. I'd like to change the language of the labels, buttons etc. while the application is already running (through a menu option). cheers, roel
If you put the different language versions of your lable text etc. into separate resource files, you can change them on the fly by reloading the appropriate resource file and modifying the appropriate text yourself. Load the initial resource file at startup using the current culture, then reload when the user changes the language selection. A little painful, as you will have to manage retrieving all the appropriate strings by key, and updating the pertinent controls yourself, but it will work. Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke