Visual Basic Concepts

Font, Display, and Print Considerations in a DBCS Environment

See Also

When you use a font designed only for SBCS characters, DBCS characters may not be displayed correctly in the DBCS version of Windows. You need to change the Font object's Name property when developing a DBCS-enabled application with the English version of Visual Basic or any other SBCS-language version. The Name property determines the font used to display text in a control, in a run-time drawing, or during a print operation. The default setting for this property is MS Sans Serif in the English version of Visual Basic. To display text correctly in a DBCS environment, you have to change the setting to an appropriate font for the DBCS environment where your application will run. You may also need to change the font size by changing the Size property of the Font object. Usually, the text in your application will be displayed best in a 9-point font on most East Asian platforms, whereas an 8-point font is typical on European platforms.

These considerations apply to printing DBCS characters with your application as well.

How to Avoid Changing Font Settings

If you do not have any DBCS-enabled font or do not know which font is appropriate for the target platform, there are several options for you to work around the font issues.

In the Traditional Chinese, Simplified Chinese, and Korean versions of Windows, there is a system capability called Font Association. With Korean Windows, for example, Font Association automatically maps any English fonts in your application to a Korean font. Therefore, you can still see Korean characters displayed, even if your application uses English fonts. The associated font is determined by the setting in \HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\fontassoc
\Associated DefaultFonts in the system registry of the run-time platform. With Font Association supported by the system, you can run your English application on a Chinese or Korean platform without changing any font settings. Font Association is not available on other platforms, such as Japanese Windows.

Another option is to use the System or FixedSys font. These fonts are available on every platform. Note that the System and FixedSys fonts have few variations in size. If the font size you set at design time (with the Size property of the Font object) for either of these fonts does not match the size of the font on the user's machine, the setting may be ignored and the displayed text truncated.

How to Change the Font at Run Time

Even though you have the options above, these solutions have restrictions. Here is an example of a global solution to changing the font in your application at run time. The following code, which works in any language version of Windows, applies the proper font to the Font object specified in the argument.

Private Const DEFAULT_CHARSET = 1
Private Const SYMBOL_CHARSET = 2
Private Const SHIFTJIS_CHARSET = 128
Private Const HANGEUL_CHARSET = 129
Private Const CHINESEBIG5_CHARSET = 136
Private Const CHINESESIMPLIFIED_CHARSET = 134
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long

Public Sub SetProperFont(obj As Object)
    On Error GoTo ErrorSetProperFont
    Select Case GetUserDefaultLCID
    Case &H404 ' Traditional Chinese
        obj.Charset = CHINESEBIG5_CHARSET
        obj.Name = ChrW(&H65B0) + ChrW(&H7D30) + ChrW(&H660E) _
         + ChrW(&H9AD4)   'New Ming-Li
        obj.Size = 9
    Case &H411 ' Japan
        obj.Charset = SHIFTJIS_CHARSET
        obj.Name = ChrW(&HFF2D) + ChrW(&HFF33) + ChrW(&H20) + _
         ChrW(&HFF30) + ChrW(&H30B4) + ChrW(&H30B7) + ChrW(&H30C3) + _
         ChrW(&H30AF)
        obj.Size = 9
    Case &H412 'Korea UserLCID
        obj.Charset = HANGEUL_CHARSET
        obj.Name = ChrW(&HAD74) + ChrW(&HB9BC)
        obj.Size = 9
    Case &H804 ' Simplified Chinese
        obj.Charset = CHINESESIMPLIFIED_CHARSET
        obj.Name = ChrW(&H5B8B) + ChrW(&H4F53)
        obj.Size = 9
    Case Else   ' The other countries
        obj.Charset = DEFAULT_CHARSET
        obj.Name = ""   ' Get the default UI font.
        obj.Size = 8
    End Select
    Exit Sub
ErrorSetProperFont:
    Err.Number = Err
End Sub

You can modify this sample code to make the font apply to other font settings, such as printing options.