Share via


Making your Winforms application Global

Recently one of our customers reported an issue that their Winforms application was not behaving properly. The size or alignments of different controls on the forms were badly affected after porting to Chinese Operating Systems resulting in overlapped controls. On top of that, due to the difference in the glyph size of the fonts, on Chinese machines there was a need to change the font size.

We discussed the issue at length and taken the feedback here are few points that we can consider making our application usable for Global customers.

  1. We strongly suggest thinking about Globalization from the early stage of Project Lifecycle. This may not be possible always however, the sooner we do it better it is.

a. Because a fonts point size varies greatly for different fonts and it is therefore recommended to leave 15-30% more space.

      2.  In case there is a sudden need, we can tweak our application to adapt to the new environment :

a. For East Asian fonts it is recommended that you use GDI instead of GDI+ for rendering by setting SetCompatibleTextRenderingDefault(false)because GDI+ tends to have rendering issues with East  Asian characters.

b. If AutoScaleMode is set to Inherit Controls scale according to the classes' parent's scaling mode. If there is no parent, automatic scaling is disabled. When you set AutoScaleMode to Font, Controls  scale relative to the dimensions of the font the classes are using, which is typically the system font.

c. Suppose you want to set a specific point size for the font. At present, we don’t have any quick way to automatically set the font size for all the forms and its child-controls. One way to change the font is through the Winforms designer. Another approach is to change the form’s font through code.  But you cannot put the code in the designer file since you should not be modifying any code in there at all.

d. In Winforms, if you do not assign a font to a form then the .NET framework will use the font returned by SystemFonts.DefaultFont.  SystemFonts.DefaultFont on an English version of Windows will return Microsoft Sans Serif 8.25.  On East Asian versions of Windows 7, the fonts returned by SystemFonts.DefaultFont are as follows:

 i.    Simplified Chinese: SimSun 9  宋体

ii.    Traditional Chinese: PMingLiU 9 新細明體

iii.    Japanese: MS UI Gothic 9

iv.    Korean: Gulim 9  굴림

 This means that if you develop a Winforms application on any  version of Windows and if you do not explicitly set the font on the form then when you run the application on English Windows 7, the font that is used will be Microsoft Sans Serif 8.25.  If you run this same application on a Simplified Chinese version of Windows then the font used by the form will be the font returned by SystemFonts.DefaultFont which is SimSun 9  宋体.

 If you don’t want the .NET Framework to use the font provided by SystemFonts.DefaultFont then you need to explicitly set the font for the form either through the designer or in code. The child controls will generally inherit the font from the parent form. Changing the font in  <FormName>.Designer.cs or <FormName>.Designer.vb is not supported. 

 The East Asian fonts’ Latin glyphs tend to be wider than their Western counter parts. If you are using the default font then there will generally be expansion when going from English systems to East Asian systems.  So as mentioned above, leaving space especially between controls that can autosize is a good idea. 

 If you specify a font like Microsoft Sans Serif 8.25 which does not contain Chinese, Japanese or Korean glyphs then font linking will be used to provide a link to a font which contains the desired East Asian glyphs.  See Globalization Step-by-Step for more details. 

 Please note that just because two fonts have the same point size does not guarantee that they will have glyphs that are the same size when displayed on the output device.  This is also mentioned in the Font Linking section of the above mentioned article.  Font sizes are not the only consideration, when localizing strings the length of translated strings will vary from language to language so it is recommended that you should leave 30 percent additional room for text expansion.  This is a general rule which works most of the time.  The exception to the rule is when using strings containing less than 10 characters like “OK” on a button.  If you add 30% you only get one character which might not be enough when translated so if the string is less than 10 characters the general rule is to leave an additional 400%.  Since these are general rules, you will need to test your application on target platforms and modify the application as needed.

 Suggested readings

Developing International Software, Second Edition

Technical Writer: Prabhat Tandon

Technical Reviewer: Marc RodMan