Reputation: 689
I want to create the localized application and want to implement a language switcher (e.g. special button). I use Visual Studio 2010 express (VB.NET).
I created simple test app with one label and one button. I set form's property "Localizable" to "True" and edited components' text in 2 languages (English as default and Russian).
I know that it is needed to add
Imports System.Threading.Thread
Imports System.Globalization
at the beginning of the Form1.vb and then use
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ru")
to enable Russian localization. But if I put this line into Button_Click event it does not change the language. Is it possible to switch between languages on event like button click or combobox change?
Thank you in advance!
Upvotes: 2
Views: 15337
Reputation: 2158
here is a possible workaround: https://social.msdn.microsoft.com/Forums/en-US/72f70870-0c0c-4eb1-886b-9db9917d080a/form-support-multilanguage-at-runtime-in-windows-based-application#8c775cc0-5e5e-4551-b5d1-52bb5c1663e8
First change CurrentUICulture, then force apply the resources of the new culture to all controls.
This code example loops through Me.Controls
, but you should loop child containers too (panels, etc).
Doing this it changes strings, locations, sizes, etc.
System.Threading.Thread.CurrentThread.CurrentUICulture = New CultureInfo("es-ES")
Dim res As ComponentResourceManager = New ComponentResourceManager(Me.GetType)
For Each aControl As Control In Me.Controls
res.ApplyResources(aControl, aControl.Name)
Next
EDITED: You can also change thread's default culture using:
CultureInfo.DefaultThreadCurrentCulture = New CultureInfo("es-ES")
doing this, all new forms you create in runtime will use this new CultureInfo.
Upvotes: 0
Reputation: 1063
Yes you can implement localization on Button Click event or on a change event. You can set the culture as
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ru-RU")
These links will help you : Globalizing and Localizing Windows Application, Walkthrough: Localizing Windows Forms, Localizing Applications
Upvotes: 3