Solved

Synchronize Multiple Textbox Scrolling

Posted on 2004-09-08
10
264 Views
Last Modified: 2012-08-13
Is it possible to synchronize 2 text boxes so that they will both always be on the same 'line' as each other even though they will contain different data...? The reason is because I have 2 text boxes and the data in each coordinates with the data in other on a line by line basis... Using normal multi line text boxes, and if possible is it possible with RTB as well?

Thanks In Advanced

Mark
0
Comment
Question by:MMKD
10 Comments
 
LVL 11

Expert Comment

by:coopzz
ID: 12004240
why don't ya just use list boxes and set the selected to the same

ie: lstBox1.listindex = lstBox2.listindex

easy
0
 

Author Comment

by:MMKD
ID: 12004292
I would use a list box, but there are some problems with that.  I need to beable to drag to select data accrost multiple lines being the major problem.. I'm starting to wonder if the only way for this to work would be to start subclassing and sending messages between each textbox....
0
 
LVL 10

Expert Comment

by:anv
ID: 12004331
please elaborate ur point

its not clear
0
 

Author Comment

by:MMKD
ID: 12004365
To make it easier to understand.  Im trying to make a Hex Editor controll... Sort of...  So for example like in a hex editor you have 2 text boxes, one containing your hex data, and one containing the Ascii, I want so when i scroll in one text box, both text boxes scroll at the same time, so the data in each text box maches up with the data in the other text box... I hope that helps make it a little more clear :/
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 500 total points
ID: 12004448
Well You can synchronize the two textboxes with a simple call to SendMessage API

Declare....

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 Const EM_LINESCROLL = &HB6

Then on a suitable event of the First TextBox call the API, say the first textbox is at line 5 then set a variable LineNumber=5 then

SendMessage(TextBox2.hwnd, EM_LINESCROLL, 0, ByVal LineNumber)

where TextBox2 is the other Textbox which you want to synchronize, the same applies for RichTextBox also just pass the handle of your RichTextBox in case you want to use RichTextBox. However, a call to the API will shift the focus to the second TextBox if you want to retain the focus on the first TextBox then explicitly set the focus back using setfocus method after the call to the API.



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:MMKD
ID: 12004607
Nice, almost exactly what i need arif eqbal, i was trying to use the SB_Lineup / SB_LineDown messages but that was doing me no good, and am using SB_Bottom for auto-scroll of text boxes.  Altho i have one more question for you.  Is there an easy way to get the number of lines in a text box? And the current line at which the text box is at? Or should i calculate this by looking for CrLf's?
0
 

Author Comment

by:MMKD
ID: 12004619
Also to add to that my last comment, also the total number of lines in the text box if there is a easier way than calculating via crlf's...?

Thanks
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12004771

Send a message EM_GETLINECOUNT ......

Private Const EM_GETLINECOUNT = &HBA

then
SendMessage(TextBox1.hwnd, EM_GETLINECOUNT, 0&, ByVal 0&)

This will give you the no. of lines
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12004806
I forgot to get current line

Private Const EM_LINEFROMCHAR = &HC9


SendMessage(TextBox1.hwnd, EM_LINEFROMCHAR, -1&, ByVal 0&)

we are sending -1 in wParam so the current line will be returned (0 based so add 1)
you can also pass a char in that line if it is unique and it will give you the line no.

0
 

Author Comment

by:MMKD
ID: 12004817
Thanks for all your help Arif_eqbal, everything working perfect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now