|
-
Jan 12th, 2000, 06:08 PM
#1
Thread Starter
New Member
I have two RichTextBox controls on a form and when I scroll one I want the other to scroll in exactly the same way. I can't find any scroll events for the RichTextBox so any other ideas would be greatly appreciated.
Thanks,
Brian.
-
Jan 12th, 2000, 11:11 PM
#2
Try changing the Value of the SelStart Property, this will reposition the Caret and Scroll the Text if neccessary, ie.
RichTextBox1.SelStart = Len(RichTextBox1) 'Scroll to the end of the Text
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 13th, 2000, 01:12 AM
#3
Thread Starter
New Member
Brilliant!
That works great, thanks very much for all your help.
Brian.
-
Jan 13th, 2000, 12:26 PM
#4
Thread Starter
New Member
Thanks for the reply.
I had thought of using the SelStart property but there were a couple of problems I couldn't figure out:
How do I know what to set it to, i.e. how do I know what the first character being displayed in the RTB is?
Also, I can't find a way of detecting when the scrollbars on a RTB are being used, the mouse click event only gets called when you click on the control itself.
Thanks,
Brian.
-
Jan 13th, 2000, 12:45 PM
#5
You could Subclass the 1st RTF Box to capture the WM_VSCROLL Message, thensend it to the 2nd RTF Box, ie.
In a Module..
Code:
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Private Const WM_VSCROLL = &H115
Public lPrevWndProc As Long
Public Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_VSCROLL Then
'Scroll the 2nd RTFBox in Unison
Call SendMessage(Form1.RichTextBox2.hWnd, WM_VSCROLL, wParam, ByVal lParam)
End If
WindowProc = CallWindowProc(lPrevWndProc, hWnd, Msg, wParam, ByVal lParam)
End Function
In the Form with 2 RTF Boxes..
Code:
Private Sub Form_Load()
Dim iIndex As Integer
RichTextBox1 = ""
For iIndex = 1 To 100
RichTextBox1.SelText = iIndex & vbCrLf
Next
RichTextBox2 = RichTextBox1
lPrevWndProc = SetWindowLong(RichTextBox1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(RichTextBox1.hWnd, GWL_WNDPROC, lPrevWndProc)
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 17th, 2000, 09:50 PM
#6
Thread Starter
New Member
Aaron,
I've been trying to extend the functionality of the code you posted so that when I scroll RTB1 it scrolls RTB2 and vice versa.
It works fine if only RTB1 controls RTB2 or if only RTB2 controls RTB1
but when I try to get them to control each other at the same time
VB just closes down (hope that made sense).
Any ideas?
Thanks,
Brian.
[This message has been edited by bdakin (edited 01-18-2000).]
[This message has been edited by bdakin (edited 01-18-2000).]
-
Jan 17th, 2000, 10:57 PM
#7
My first guess would be it's causing an Infinite loop, think about it..
You Scroll Box1 which sends a Message to Box2, which Scrolls Box2, which sends a Message to Box1, which Scrolls Box1, etc, etc..
You would need an Identifier so you would know when it's you who is programmatically scrolling either Box, then you could disregard the Scroll Message, i.e
Use a Private Boolean Variable in the Module, set this to True when you send a Scroll Message, then Check to see if this value is True, if it is, it means you shouldn't process the Scroll Message, then set it to False, ready to process the next Scroll Message, Preventing an Infinite loop.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 19th, 2000, 09:08 PM
#8
Thread Starter
New Member
That did the trick, pretty obvious now that I think about it, thank you very much.
Brian.
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
|