Do they have to be TextAreas? Can they be Listboxes? I don’t think the TextArea will give you the events that you need.
Another option is to move the feature to a Timer that runs, say, every 100 ms that checks the position of the TextAreas and the Scrollbar. Whichever TextArea has focus would set the values of the other two controls, and the scrollbar would set it if neither have focus.
Following along Kem’s timer idea; something like this on the Timer Action event:
If TextArea1(0).ScrollPosition <> pLastPosition Then
TextArea1(1).ScrollPosition = TextArea1(0).ScrollPosition
pLastPosition = TextArea1(1).ScrollPosition
ElseIf TextArea1(1).ScrollPosition <> pLastPosition Then
TextArea1(0).ScrollPosition = TextArea1(1).ScrollPosition
pLastPosition = TextArea1(0).ScrollPosition
Else
// do nothing
End If
pLastPosition is a property to remember the last known position
I experimented several solutions, including setting one textarea with the other one scrollposition when it is modified. The result is choppy and erratic.
The very best result is to use one scroll bar that is set to the maximum ScrollPosition in the window Open event like so :
Sub Open()
dim oldscroll as integer = TextArea1.ScrollPosition
TextArea1.ScrollPosition = 10000
scrollmax = TextArea1.ScrollPosition
TextArea1.ScrollPosition = oldscroll
Scrollbar1.Maximum = scrollmax
Scrollbar1.Value = oldscroll
End Sub
Scrollmax is an integer window property
Both TextAreas vertical scrollbars have been disabled.
Then this in the scrollbar :
Sub ValueChanged()
Textarea1.ScrollPosition = me.value
Textarea2.ScrollPosition = me.value
End Sub
Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean
me.value = me.value-deltaY
End Function