11.2 Localizing Windows Forms Controls

 <  Day Day Up  >  

You want to localize the text displayed on controls and display the correct language based on a user 's culture information.


Technique

After creating your Windows Forms application, select the form in the form designer and set the Localizable property to true . Use the form designer to add controls and set the text using the language you want to use as the default. To add text for a different language, select the form and set the Language property to the language you want to localize to. Change the Text property for each control to the correct string for that language. You can continue adding new languages by changing the Language property of your Windows Form.

Comments

Setting actual translation issues aside, localizing a Windows Form is a rather trivial process. Simply set the Localizable property to true and then change the Text property for each control as you change the Language property of the form. However, even though the process is relatively simple, it can be tedious , especially if your application is large and supports many languages. Fortunately, there is a way to speed up this process. Whenever you change the Language property of your Windows Form, a new file is created within your project's source directory whose filename is a concatenation of your form's implementation class name and the culture ISO identifier followed by a .resx extension. This .resx file is an Extensible Markup Language (XML) file used to store that culture's language information. In other words, by simply editing the correct data/value pairs within the .resx file, you can localize a language without having to use the forms designer.

Directly editing the generated .resx files can be a real time-saver, but you should ensure that the controls display the strings correctly by verifying them within the forms designer. A small string in one language can be a very large string in a different language, and the control that uses that string might not be large enough. Fortunately, you don't have to change the size for that control in every language to accommodate the larger string for that single language. You can also use resource files, .resx files, to store object data, which in this case would be the Size object defined within a Windows Form control. To resize the control for that single language, set the Language property to the correct language and resize the control. The control is then resized only for that language. Recipe 11.5, "Using Fallback Resource for Unsupported Regions," discusses how the .NET Framework uses resource files to load the correct resources at runtime.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net