|Title||Change a form's locale resources at run time in VB .NET|
|Description||This example shows how to change a form's locale resources at run time in VB .NET. It uses a ComponentResourceManager to load the resources for different locales.|
|Keywords||locale, internationalization, globalization, ComponentResourceManager|
When the user clicks the radGerman radio button, the program creates a new CultureInfo object for the German language in Germany (culture de-DE). It makes a ComponentResourceManager to work with the form's type. It saves the form's location, uses the manager's ApplyResources method to load the form's resources (they are prefixed by "$this" in the resource file), and restores the form's location.
Next the form loops through the form's controls, using the ApplyResources method to load each of their resources.
The code to that switches to English is simliar except it uses the culture en-US.
' Switch to German.
Private Sub radGerman_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
' Make the CultureInfo.
Dim culture_info As New CultureInfo("de-DE")
' Make a ComponentResourceManager.
Dim component_resource_manager As New _
' Save the current location.
Dim old_location As Point = Me.Location
' Apply resources to the form.
component_resource_manager.ApplyResources(Me, "$this", _
' Restore the location.
Me.Location = old_location
' Apply resources to the form's controls.
For Each ctl As Control In Me.Controls