Help and Support
 

powered byLive Search

PRB: RichTextBox Control Saves Locale Setting When Created

Article ID:189480
Last Review:July 15, 2004
Revision:3.1
This article was previously published under Q189480
On This Page

SYMPTOMS

Text entered into a RichTextBox control at run-time uses a keyboard layout that is different than the current setting.

Back to the top

CAUSE

When the RichTextBox control was initially added to the form, the then- current keyboard setting was saved with the text in the text property of the control.

Back to the top

RESOLUTION

There are several possible workarounds depending on the version of the control you are working with.

With version 6.0 of the control there are two workarounds:

1.When adding the control to a form, delete the text in the text property. If the control has no text, the layout setting will not be saved.
2.Select all the text in the RichTextBox control and set the keyboard locale to the language desired.
With Version 5.0 and earlier of the control, use the following code to check the keyboard layout of the form and use it as the check value. Then check the keyboard layout of the RichTextBox control and change it to the form's value if different.

Back to the top

Step-by-Step Example

1.Add the following code to General Declarations section of the form module:
      Option Explicit

      Private Declare Function GetKeyboardLayoutName Lib "user32" Alias _
      "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long

      Private Declare Function LoadKeyboardLayout Lib "user32" Alias _
      "LoadKeyboardLayoutA" (ByVal pwszKLID As String, _
      ByVal flags As Long) As Long

      Dim K1 As String * 10
      Dim KybdOriginal As Long
						
2.Add the following code to the form Load event procedure:
      K1 = Space$(10)
      KybdOriginal = GetKeyboardLayoutName(K1)
						
3.Add the following code to the GotFocus event procedure of the RichTextBox control:
      Dim K2 As String * 10
      Dim KybdCode As Long

      K2 = Space$(10)
      KybdCode = GetKeyboardLayoutName(K2)

      If (K1 <> K2) Then KybdCode = LoadKeyboardLayout(K1, 1)
						
This should reset the keyboard layout setting for the RichTextBox control to match the layout used by the form.

Back to the top

STATUS

This behavior is by design. The RichTextBox control saves the language setting when text is saved.

Back to the top

MORE INFORMATION

When a RichTextBox control is added to a form, default text is added to the text property. When the form is saved the RTF data format includes the keyboard settings as part of the font information.

Version 6.0 of the control does not save the keyboard setting if the text property of the control is empty. Previous versions of the control saved the setting regardless of the contents of the text property.

The keyboard (Locale) setting can be changed in Control Panel/Regional Settings.

Back to the top

REFERENCES

Online Help for Microsoft Visual Basic, versions 4.0 and 5.0

Books Online for Microsoft Visual Basic 5.0 and 6.0

Back to the top


APPLIES TO
Microsoft Visual Basic 5.0 Learning Edition
Microsoft Visual Basic 6.0 Learning Edition
Microsoft Visual Basic 5.0 Professional Edition
Microsoft Visual Basic 6.0 Professional Edition
Microsoft Visual Basic 5.0 Enterprise Edition
Microsoft Visual Basic 6.0 Enterprise Edition
Microsoft Visual Basic 4.0 Standard Edition
Microsoft Visual Basic 4.0 Professional Edition
Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

Back to the top

Keywords: 
kbprb KB189480

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.