|
-
Aug 1st, 2000, 02:37 AM
#1
Thread Starter
New Member
I'm looking for help to automatically scroll through a rich text box. What I need to do is after I find a piece of text I'd like to scroll the line that text is in to the top of the rich text box. Sort of like the .topindex property of a list box.
For example if I'm looking for the text "found_me" and find it in line 6 how would I move line 6 and everything after it to the top of the rich text box. Every line before line 6 will then scroll out of view. No lines will be deleted in the process, just visible or not visible.
I can find the text I just can't figure out how to scroll through the lines. Thanks for your help, it is greatly appreciated.
-
Aug 1st, 2000, 01:32 PM
#2
Code:
'Scroll Richtextboxes Pixel by Pixel
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const SIF_RANGE = &H1
Const SB_VERT = 1
Dim lHeight As Long, OnePixel As Long
Dim S As SCROLLINFO
Private Sub ScrollUp(delay As Long)
Sleep delay
With rtb1(0)
.Top = .Top - OnePixel
If .Top + .Height = 0 Then
.Move 0, 0
rtb1(1).Visible = False
End If
If .Top + .Height <= Picture1.Height Then
rtb1(1).Top = .Top + .Height
rtb1(1).Visible = True
End If
End With
End Sub
Private Sub Form_Load()
'CHANGE TO YOUR OWN FILE NAME
rtb1(0).LoadFile App.Path & "\mydoc.rtf", rtfRTF
Picture1.Move rtb1(0).Left, rtb1(0).Top, rtb1(0).Width, rtb1(0).Height
Set rtb1(0).Container = Picture1
OnePixel = Screen.TwipsPerPixelY
S.cbSize = Len(S)
S.fMask = SIF_RANGE
Do
Call GetScrollInfo(rtb1(0).hwnd, SB_VERT, S)
If S.nMax = 0 Then Exit Do
lHeight = S.nMax * OnePixel
rtb1(0).Height = lHeight
Loop
If lHeight = 0 Then lHeight = rtb1(0).Height
Text1 = lHeight / OnePixel
rtb1(0).Move 0, 0
Load rtb1(1)
rtb1(1).Visible = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Usage:
'Private Sub Command1_Click()
' Do
' DoEvents
' ScrollUp 50
' Loop
'End Sub
-
Aug 1st, 2000, 04:10 PM
#3
Thread Starter
New Member
Thanks Matthew,
Intersting code. When I click the command button the rich
text box scrolls up and out of the picture box as a
second rich text box chases the first. The effect is like
watching a tv that needs its vertical hold adjusted.
Unfortunately, this code doesn't help. I need the text in
the box to scroll (or move instantly) into view when a
string is found and take the position of the top line in the
text box revealing about 10 lines of before unseen text in the
box. The number 10 is just an example, the lines of text
that will be revealed depends on the size of the rich text
box with respect to the user's screen size.
Also use the above code with care. If I use it with a text
box that has scroll bars my computer freezes when command1
is clicked.
Thanks again for the code, I learned alot from it.
John
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|