Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way where we can Sync scroll Label, TextBox or RichTextBox with ListBox ScrollBar?

ScrollBar should be visible only for ListBox and (Label, TextBox or RichTextBox should not have any scollbar)

I've mentioned Label, TextBox or RichTextBox, anyone could work for me, whichever is compatible to sync scroll with ListBox.

What I have tried:

I tried 2 RichTextBox sync but thats not what I'm looking for, though, I've also tried 2 ListBox Scroll and I've Hide 1 ScrollBar Scroller but that is slow and not scrolling together, there's a delay of some milliseconds.
Posted
Updated 1-Nov-17 6:32am

1 solution

I got this working for a ListBox and a RichTextBox but only one way... Meaning that scrolling the RTB will scroll the LB but not the opposite
Here is the code... Put it in the VScroll function of the RTB
VB
Dim lineNumber As Integer = 0
lineNumber is a global variable...
VB
Dim firstVisibleChar As Integer = RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
lineNumber = RichTextBox1.GetLineFromCharIndex(firstVisibleChar)
ListBox1.TopIndex = lineNumber

I know we can simplify this code more, but I've made it a bit longer so that anyone can easily understand it...
 
Share this answer
 
Comments
Shaikh Javed Aryan 6-Nov-17 9:59am    
This is great but I wanted Listbox to RichTextBox
Mrunal Sonawane 6-Nov-17 11:19am    
But you can try one thing... hide the scrollbar of ListBox and put the RTB on the right hand side so that you have only one scrollbar visible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900