PRB: RichTextBox Control Saves Locale Setting When Created
ID: Q189480
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, versions 4.0, 5.0
SYMPTOMS
Text entered into a RichTextBox control at run-time uses a keyboard layout
that is different than the current setting.
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.
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:
- 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.
- 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.
Step-by-Step Example
- 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
- Add the following code to the form Load event procedure:
K1 = Space$(10)
KybdOriginal = GetKeyboardLayoutName(K1)
- 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.
STATUS
This behavior is by design. The RichTextBox control saves the language
setting when text is saved.
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.
REFERENCES
Online Help for Microsoft Visual Basic, versions 4.0 and 5.0
Books Online for Microsoft Visual Basic 5.0 and 6.0
Additional query words:
kbDSupport RTF richtext richedit kbVBp400 kbVBp500 kbVBp600 kbdss kbCrtl kbVBp
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbprb