Share via

Slide 2 scrollbars at same time with different values

A R C 1 Reputation point
2021-06-09T06:58:00.743+00:00

I use this simple code to move 2 scrollbars of different Richtextboxes at same time, the trouble comes when one of them has more longer text, any suggestion? how I can get and implement the percentage to reach the second position start/middle/ending equivalent position at same time??

  1. Const EM_GETSCROLLPOS As Integer = WM_USER + 221
  2. Const EM_SETSCROLLPOS As Integer = WM_USER + 222
  3. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByRef lParam As Point) As Integer
  4. Private Sub RichTextBox1_VScroll(sender As Object, e As EventArgs) Handles RichTextBox1.VScroll
  5. Dim pt As Point
  6. SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, pt)
  7. SendMessage(RichTextBox2.Handle, EM_SETSCROLLPOS, 0, pt)
  8. End Sub
  9. Private Sub RichTextBox2_VScroll(sender As Object, e As EventArgs) Handles RichTextBox2.VScroll
  10. Dim pt As Point
  11. SendMessage(RichTextBox2.Handle, EM_GETSCROLLPOS, 0, pt)
  12. SendMessage(RichTextBox1.Handle, EM_SETSCROLLPOS, 0, pt)
Developer technologies | VB

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.