Share via


How to: Set the Culture and UI Culture for Windows Forms Globalization

The two culture values of a Visual Basic or Visual C# application determine what resources are loaded for an application and how information like currency, numbers, and dates is formatted. The resources loaded are determined by the UI culture setting, and the formatting options are determined by the culture setting. The first place an application will search for culture values is the CurrentCulture and CurrentUICulture properties. You can set these values in code as shown in the following procedure.

The CurrentCulture property's default value is the operating system's User Locale, which is set in the Regional Options control panel. The CurrentUICulture property's default value is the operating system's user interface (UI) language, which is the language of your operating system UI. On Windows 2000 and Windows XP MultiLanguage Edition, the CurrentUICulture defaults to the current user UI language settings.

In some instances, you may want to have most of your application change according to the operating system's or user's culture settings, but also have a number or date that does not change. You can have culture-specific classes format the information with the invariant culture, which is associated with the English language but no particular region. For more information about these classes, see Formatting for Different Cultures and System.Globalization. For more information about the invariant culture, see InvariantCulture. For information about possible culture settings, see CultureInfo.

To set formatting options appropriate for a specific culture

  1. If you want to override the settings of the user or operating system, set the CurrentCulture and CurrentUICulture properties.

    Usually, you want to specify a culture so that every part of the application's UI is appropriate to that culture. So you must set the culture before the InitializeComponent method is called.

    ' Put the Imports statements at the beginning of the code module
    Imports System.Threading
    Imports System.Globalization
    ' Put the following code before InitializeComponent()
    ' Sets the culture to French (France)
    Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR")
    ' Sets the UI culture to French (France)
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR")
    
    // Put the using statements at the beginning of the code module
    using System.Threading;
    using System.Globalization;
    // Put the following code before InitializeComponent()
    // Sets the culture to French (France)
    Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
    // Sets the UI culture to French (France)
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
    

    Note

    The culture value must always be a specific culture (such as "fr-FR"), not a neutral culture (such as "fr"). A neutral culture such as "fr" is problematic, because it can apply to all French-speaking cultures, and different currencies are used in France, Belgium, and Quebec.

  2. Call formatting methods with the invariant culture for any strings that should appear unchanged regardless of the CurrentCulture property's value.

    Dim MyInt As Integer = 100
    Dim MyString As String = MyInt.ToString("C", CultureInfo.InvariantCulture)
    MessageBox.Show(MyString)
    
    int MyInt = 100;
    string MyString = MyInt.ToString("C", CultureInfo.InvariantCulture);
    MessageBox.Show(MyString);
    

See Also

Reference

CurrentCulture

CurrentUICulture

CultureInfo

Other Resources

Globalizing Applications

Globalizing and Localizing Applications

Globalizing Windows Forms