Solved

Synchronize Multiple Textbox Scrolling

Posted on 2004-09-08
10
260 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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

13 Experts available now in Live!

Get 1:1 Help Now