How to switch form language on button click in VB.NET?
I want to create a localized application and want to implement a language switcher (like a custom button). I am using Visual Studio 2010 express (VB.NET).
I created a simple test app with one label and one button. I set the "Localizable" property to "True" and edited the text of the components in two languages ββ(English by default and Russian).
I know what to add
Imports System.Threading.Thread
Imports System.Globalization
at the beginning of Form1.vb and then use
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ru")
to enable Russian localization. But if I put this line in the Button_Click event it doesn't change the language. Is it possible to switch between languages ββin an event, for example by clicking a button or changing icons?
Thank you in advance!
source to share
Yes, you can implement localization in the Button Click event or in the change event. You can set culture as
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ru-RU")
These links will guide you: Globalizing and Localizing a Windows Application , Walkthrough: Localizing Windows Forms , Localizing Applications
source to share
a workaround is possible here: 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
Modify CurrentUICulture first, then force the new culture resources to all controls.
This code example goes through Me.Controls
, but you have to create child containers (panels, etc.) as well.
By doing this, it changes lines, 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 the default thread culture using:
CultureInfo.DefaultThreadCurrentCulture = New CultureInfo("es-ES")
By doing this, any new forms you create at runtime will use this new CultureInfo.
source to share