• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 410
  • Last Modified:

Synchronize Multiple Textbox Scrolling

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
MMKD
Asked:
MMKD
1 Solution
 
coopzzCommented:
why don't ya just use list boxes and set the selected to the same

ie: lstBox1.listindex = lstBox2.listindex

easy
0
 
MMKDAuthor Commented:
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
 
anvCommented:
please elaborate ur point

its not clear
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MMKDAuthor Commented:
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
 
arif_eqbalCommented:
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
 
MMKDAuthor Commented:
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
 
MMKDAuthor Commented:
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
 
arif_eqbalCommented:

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
 
arif_eqbalCommented:
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
 
MMKDAuthor Commented:
Thanks for all your help Arif_eqbal, everything working perfect.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now