How to Localize Windows Forms and Change the Language at Runtime
Localization is the process of customizing your application to a particular language, culture or locale. Visual Studio provides support for localizing Windows Forms with much ease. In this article, we will see how to localize windows forms and give the user the ability to change to his preferred language at runtime.
When you run a localized application, the appearance is determined by two culture values. The UICulture property is used to specify which resource files will be loaded for the form. The Culture property, on the other hand, determines how strings such as dates, numerals, and currency amounts are formatted.
Let us see the steps required to create a localized form. You can then expand this example and adopt the same approach for the rest of the forms in your project.
Step 1: Open Visual Studio > File > New > Project. In the Project Types pane, choose the language of your choice (Visual C# or Visual Basic). In the Templates pane, choose Windows Application. Choose a name and location for the project and click OK.
Step 2: With the form opened, set its ‘Localizable’ property to True. Drag a Label control from the Toolbox, and set its Text property to ‘Hello’.
Note: By default, the Language property of the form is set to ‘(Default)’.
Step 3: Now set the form's ‘Language’ property to French (France). Set the label's Text property to ‘bonjour’.
Once again, set the form's Language property, but this time to Spanish (Spain). Set the button's Text property to holà.
Build the Solution. Expand the node in Form1.vb/Form1.cs. As you observe, the resource files appear underneath Form1.vb/Form1.cs. Form1.resx is the resource file for the default culture, Form1.fr-FR.resx is the resource file for French (France) and Form1.es-ES.resx is the resource file for Spanish (Spain). If you cannot see these files for some reason, click the ‘Show All Files’ button in Solution Explorer.
Step 4: Now set the form's ‘Language’ property back to (Default). Drag a ‘ComboBox’ from the Toolbox to the form.
In the Form_Load() add the following code :
private void Form1_Load(object sender, EventArgs e)
comboBox1.SelectedIndex = 0;
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
comboBox1.SelectedIndex = 0
Also add references to the namespaces:
Step 5: Now add a SelectedIndexChanged event handler to the ComboBox. Write the following code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
if (comboBox1.SelectedItem.ToString() == "English")
else if (comboBox1.SelectedItem.ToString() == "Spanish")
private void ChangeLanguage(string lang)
foreach (Control c in this.Controls)
ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
resources.ApplyResources(c, c.Name, new CultureInfo(lang));
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If comboBox1.SelectedItem.ToString() = "English" Then
ElseIf comboBox1.SelectedItem.ToString() = "Spanish" Then
Private Sub ChangeLanguage(ByVal lang As String)
For Each c As Control In Me.Controls
Dim resources As ComponentResourceManager = New ComponentResourceManager(GetType(Form1))
resources.ApplyResources(c, c.Name, New CultureInfo(lang))
As you observe, every time the user selects a new language, the ChooseLanguage() method is called. In this method, we loop through each control on the form and use the ComponentResourceManager to enumerate through the resources for an object. We then use the ApplyResources method to apply a resource's value to the corresponding property of the object. One of the overloads of the ApplyResources accepts 3 parameters: the control that contains the property value to be applied; a string that contains the name of the object to look up in the resources and a culture for which to apply resources.
Note: Notice that each culture name(es-ES) consists of two parts. The first part represents the language code and the second part represents the country/region code. If you specify a culture name and do not provide a country/region code—for example, "en" —then that represents a 'neutral culture'. If you provide both a language code and a country/region code—for example, "es-ES", then that represents a 'specific culture'.
Well that’s it. Run the application and choose your preferred language from the combobox. You will see that the label changes values as set by you while creating the resources. I hope you liked the article and I thank you for viewing it.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!