| The instrinsic
TextBox control that VBCE provides has a bug (BUG: TextBox Does Not Scroll to the Caret
Position Q181945) that causes it not to scroll to the caret position when the SelStart is
set to a location that is out of the current view of the TextBox. This prevents the programmer from being able to do
a number of things, the major one is incorporating a find method. What good is placing the
caret at the bottom of a document and/or highlighting a word if the caret or the
highlighted word is out of view?
Fortunately, our little friend the Windows
Message comes to the rescue once again. Sooner or later you'll need the functions of the VBCE.COM VBCEMiscUtility control, a control for use in
VBCE, and this is just another one of those situations.
By sending the TextBox an EM_SCROLLCARET
message, the textbox will scroll so that the caret is in view. Simply place an instance of
the VBCEMiscUtil control on your main form, paste the ScrollTextBox routine into your code
somewhere, and then call it like this:
'Scroll to end of textbox
ScrollTextBox Text1
Public Sub ScrollTextBox(TBox)
'EM_SCROLLCARET = &HB7
'Works around the SelStart scrolling Bug
'Scrolls the text box so that the
'caret (cursor) is in view
Call VBCEUtil1.SendMessageLong( _
TBox.hwnd,
&HB7, 0, 0)
End Sub |
 |
 |
 |
When the bugs get tough,
the tough get coding! |
|