Windows Forms Localization

If you are an experienced Windows Forms developer, maybe you already faced the localization problem with this technology. There are different ways for localizing a Windows Forms application, but basically all of them rely on managed resources. The easiest way for localizing a Windows Forms application is to take advantage of the Visual Studio Designer so that the IDE generates the appropriate resources files for you. An example is of course the best way for providing explanations; the goal of this an example is to localize a Windows Forms application in both English and Italian. Run Visual Studio 2010, create a new Windows Forms project with Visual Basic 2010, and name it WindowsFormsLocalization. Follow these steps:

1. Drag a Button from the toolbox onto the new form surface, and set its Text property as Localized button.

2. Drag a Label from the toolbox onto the new form surface, and set its Text property as Localized label.

3. Select the form, and in the Properties window set its Localizable property as True; then set its Language property as Italian.

4. Select the Button and set its Text property as Pulsante localizzato (in Italian).

5. Select the Label and set its Text property as Etichetta localizzata.

6. Build the project and enable the Show All Files view in Solution Explorer.

You notice that Visual Studio has generated a new it-IT subfolder under BinDebug (or BinRelease) containing a satellite assembly where localized resources are stored. Moreover, Visual Studio generated a new localized resources file for the current form named Form1.it-IT.resx storing the localized information for design time. If you try to run the application, you notice that it is still localized in English. This is because you need to explicitly assign in code the new localized culture. This can be accomplished by adding the following code (which requires an Imports System.Globalization directive) at the beginning of the application startup, which is typically the constructor, before the InitializeMethod is invoked:

image

The code simply assigns to the current thread the new culture information that will be retrieved from the related subfolder and satellite assembly. Figure 36.1 shows how the application looks with localized controls.

Figure 36.1 The localized Windows Forms application in action.

image

Windows Forms localization is straightforward because you can take advantage of the Visual Studio Designer. Unfortunately this is not the same in WPF applications, where a number of manual steps are required, as explained in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.63.106