Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleChange a form's locale resources at run time in VB .NET
DescriptionThis 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.
Keywordslocale, internationalization, globalization, ComponentResourceManager
CategoriesVB.NET, Controls
 
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 _
    radGerman.CheckedChanged
    ' Make the CultureInfo.
    Dim culture_info As New CultureInfo("de-DE")

    ' Make a ComponentResourceManager.
    Dim component_resource_manager As New _
        ComponentResourceManager(Me.GetType)

    ' Save the current location.
    Dim old_location As Point = Me.Location

    ' Apply resources to the form.
    component_resource_manager.ApplyResources(Me, "$this", _
        culture_info)

    ' Restore the location.
    Me.Location = old_location

    ' Apply resources to the form's controls.
    For Each ctl As Control In Me.Controls
        component_resource_manager.ApplyResources(ctl, _
            ctl.Name, culture_info)
    Next ctl
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated