index > Visual Basic General > Synchronize textbox scrolling

Synchronize textbox scrolling

I have two multiline textboxes, no wrap (horizontal/vertical scrollbars)

Is there a way I can sync the scrolling so when I scroll one, the other one scrolls?

Ro0ke

OK, unfortunately, the regular textbox control doesn't have scroll events. That's a pain. The RichTextbox control, on the other hand, does. So this is easier with a rich text control. You can do the following:

Const WM_USER As Integer = &H400

Const EM_GETSCROLLPOS As Integer = WM_USER + 221

Const EM_SETSCROLLPOS As Integer = WM_USER + 222

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

Private Sub RichTextBox1_VScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.VScroll

Dim pt As Point

SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, pt)

SendMessage(RichTextBox2.Handle, EM_SETSCROLLPOS, 0, pt)

End Sub

Every time you scroll (vertically) on richtextbox1, you set the scroll position on richtextbox2. You can also do the same in the HScroll event to capture horizontal scrolling.

If you *need* to do this with a regular textbox, then you have to create a custom textbox by inheriting the textbox class, and overriding the wndproc method to look for scrolling messages, then fire a custom scrolling event. To keep it simple, I'd rather use the richtextbox control.




-Rob Teixeira
Rob Teixeira

I would much rather use a RichTextbox, but I can't. I also need to change the width of the caret (so it resembles a block) and as far as I know, this can only be done in a regular textbox.

Ro0ke
You can do the same thing with a textbox, but like I said, you need to create your own scroll events for the textboxes by overriding the wndproc method and looking for windows scroll messages (like WM_VSCROLL and WM_HSCROLL). Other than that, the same technique should work.


-Rob Teixeira
Rob Teixeira
reply 4

You can use google to search for other answers

 

More Articles

• extracting symbols
• Using Visual Studio VB with Access 2003 -> General Questions
• Access denied error when trying to create new outlook mail item f...
• XML in Treeview
• Front-end Framework
• How To run VB.Net Application on a PC without installing VB
• shaped controls
• OleDbDataAdapter Wizard - select command vs. stored Procedures
• VB works in 2k, Not in 2k3 - Experts please help!
• Getting Data from SQL Server through .Net to Excel
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• mp3 encoder sample application
• Access --> SQL
• I need Help, database
• Triggering events by usb or serial ports?
• print dialog box
• Sending mail throught Visual Basic
• Dataset Problem
• developing a flash player!
• Traversing Arrays
• saving datatable to a new ms access table
• Server exploer: adding stored procedures
• Blackjack starter kit
• LPVOID datatype. What would appropriate
• How can I copy an entire table row to th
• XML Help Needed

Hot Articles

• [OTP] Visual Web Developer : How do I ge
• How to use Sybase ASE11 to a VB project
• Change Border Color
• Add a button in a binded ComboBox
• Visual Basic and Reports question
• How do I create events for an array?
• My Email App Sends to Junk and Spam only
• Getting Started???
• playing mp3 and mpeg
• Sending text to another PC
• VB 2003 Deployment
• How to get DLL files version./.net compa
• mdf file not attached when deployed usin
• Undo disabled using Worksheet_Change eve
• can i use scrollbar on a frame?

Recommend Articles

• How Create setup for a vb.net applicatio
• Why does my form close after the form.show
• Reading Weather RSS Feed
• Iterate through querytables
• Queston about "nothing"
• Exporting to word
• Create a custom keyboard layout
• How to make a .NET component binary comp
• simulate Excel New Web Query in VB2005
• Equivalent of mscomctl in VB.NET 2005
• User session logon time!
• validation controls in windows forms2.0
• Pipe Buffer
• RSS in Visual Basic Express?
• Two-pronged Question