Improve company productivity with a Business Account.Sign Up

x
?
Solved

Synchronize Multiple Textbox Scrolling

Posted on 2004-09-08
10
Medium Priority
?
432 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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 

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 2000 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
 

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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

595 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