[RESOLVED] positioning within the Rich Text Box (RTB)
When using the rtb.Find method, is places the insertion point at the beginning of the matched text. However, it just pulls this matched text into view. Leaving it at the bottom of the rtb control, instead of positioning/ scrolling the found text to the top so that the text below it is also in view.
Is there anyway to force a repositioning/scroll after the text is found, or somehow ensure that the matched text is placed at the top?
Re: positioning within the Rich Text Box (RTB)
VB Code:
Option Explicit
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, lParam As Long) As Long
Private Const EM_LINESCROLL = &HB6
Private Const EM_GETFIRSTVISIBLELINE = &HCE
Private Sub Command1_Click()
Dim lng1stVisible As Long
Dim lngLineWithWord As Long
With RichTextBox1
.Find "the word you want"
' Get the line number that contains the word
lngLineWithWord = .GetLineFromChar(.SelStart)
' Get the line number of the 1st visible line
lng1stVisible = SendMessageLong(.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&)
' Scroll
SendMessageLong .hwnd, EM_LINESCROLL, 0, ByVal lngLineWithWord - lng1stVisible
End With
End Sub
Re: positioning within the Rich Text Box (RTB)
Ohhhhh YEAaaaaaaaaaaa....
Many Thanks Marty :D
Yikes...18 thousand posts...
And since you were so quick with the EM_'s maybe you are familiar with the statusbar and tooltip messaging
i dont suppose you saw my other post about obtaining the window handle of the tooltips for a STATUSBAR did you? :confused:
Re: positioning within the Rich Text Box (RTB)
You're welcome. Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.