Scroll 2 textboxes off a single scroll bar 
Author Message
 Scroll 2 textboxes off a single scroll bar

Hi,

I want to use a single scroll bar to scroll 2 text boxes
as though they are 'locked' together - this is in VB6.

No problem using subclassing, just could not seem to find
the right messages to grab.

Thanks,

Chuck



Sat, 30 Jul 2005 09:10:32 GMT  
 Scroll 2 textboxes off a single scroll bar
Is M_LINESCROLL what you are after?

HOWTO: Extend the Scrolling Capabilities of a TextBox Control
http://support.microsoft.com/default.aspx?scid=KB;EN-US;161270

Would you tell us more about the problem? How do you "lock the textboxes
together"?

Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provide "AS IS" with no warranties, and confers no rights.

--------------------
| Content-Class: urn:content-classes:message

| Xref: cpmsftngxa06 microsoft.public.vb.controls:144293
| X-Tomcat-NG: microsoft.public.vb.controls
|
| Hi,
|
| I want to use a single scroll bar to scroll 2 text boxes
| as though they are 'locked' together - this is in VB6.
|
| No problem using subclassing, just could not seem to find
| the right messages to grab.
|
| Thanks,
|
| Chuck
|
|



Sat, 30 Jul 2005 16:27:40 GMT  
 Scroll 2 textboxes off a single scroll bar
I suppose you are looking for something similar to Visual SourceSafes
diff UI.
Here is an outline of what you can do :

1. Create two textboxes with MultiLine set to true. Lets call then
txtLeft, txtRight.

2. Position them appropriately side by side.

3. Use GetWindowLong/SetWindowLong and GWL_STYLE to get rid of the
vertical scrollbar of the txtLeft.

4. Now subclass the container form and trap WM_COMMAND (!!), and look
for EN_HSCROLL and EN_VSCROLL in wParam, lParam will have the handle
of the edit control being scrolled.

You will need to make sure that there isn't a run-away looping when
you try to sync the scroll position in the editboxes.

Though I haven't tried this myself ;-), I think this is reasonable
direction. Do let me know if it worked/helped.

Vikram Lele
------------------------------------------------
Providing Components For Your Software Solutions
http://www.viklele.com

Quote:

> Hi,

> I want to use a single scroll bar to scroll 2 text boxes
> as though they are 'locked' together - this is in VB6.

> No problem using subclassing, just could not seem to find
> the right messages to grab.

> Thanks,

> Chuck



Sat, 30 Jul 2005 17:00:12 GMT  
 Scroll 2 textboxes off a single scroll bar


Wed, 18 Jun 1902 08:00:00 GMT  
 Scroll 2 textboxes off a single scroll bar
Thanks for the info.  The solution required a combination
of both solutions - it works great.

I have included the source below in case anyone wants to
do this.  I also want to put in a plug for the subclasser
from Desaware.  It is written in C and is excellent.  No
problems using it in the IDE and it is simply a fine
piece of code.  

Solution:
1. Place 2 txtboxes on the form - enable multiline on
both.  (I called them txtTerm(0) & txtTerm(1))
2. Set to view the vscroll on the the left
3. Do not view the vscroll on the right.
4. Subclass the left and look for EN_VSCROLL.  This only
takes a click on the Desaware subclasser.
5. I recommend using 'POST-DEFAULT' processing for this
application so that the scroll bar has a chance to update
the left text box before the subclass function is called.
6. Add the following function

Private Sub SubClassTxtScroll_WndMessage(wnd As Long, Msg
As Long, wp As Long, lp As Long, retval As Long, nodef As
Integer)

    Dim sts As Long
    Dim lTopLineLeft As Long
    Dim lTopLineRight As Long
    Dim lDifference As Long

    ' Get the line numbers
    lTopLineLeft = SendMessage(Me.txtTerm(0).hWnd,
EM_GETFIRSTVISIBLELINE, 0, 0)
    lTopLineRight = SendMessage(Me.txtTerm(1).hWnd,
EM_GETFIRSTVISIBLELINE, 0, 0)

    ' determine the difference between the lines
    lDifference = lTopLineLeft - lTopLineRight
    If (lDifference = 0) Then
        GoTo exitPt
    End If

    ' move the right text box so that the top lines match
    sts = SendMessage(Me.txtTerm(1).hWnd, EM_LINESCROLL,
0, lDifference)

exitPt:
End Sub

Best regards,

Chuck



Sun, 31 Jul 2005 01:05:08 GMT  
 Scroll 2 textboxes off a single scroll bar
Whoa!  Why do ...

   ' determine the difference between the lines
    lDifference = lTopLineLeft - lTopLineRight
    If (lDifference = 0) Then
        GoTo exitPt
    End If

    Sendmessage ....

exitPt:
End Sub

...when you can nuke the Goto entirely?  Since you bail if diff = 0, you
must then process if diff <> 0, so ...

   ' determine the difference between the lines
    lDifference = lTopLineLeft - lTopLineRight
    If lDifference <> 0 Then
            Sendmessage ....
    End If

End Sub

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


# Thanks for the info.  The solution required a combination
# of both solutions - it works great.
#
# I have included the source below in case anyone wants to
# do this.  I also want to put in a plug for the subclasser
# from Desaware.  It is written in C and is excellent.  No
# problems using it in the IDE and it is simply a fine
# piece of code.
#
# Solution:
# 1. Place 2 txtboxes on the form - enable multiline on
# both.  (I called them txtTerm(0) & txtTerm(1))
# 2. Set to view the vscroll on the the left
# 3. Do not view the vscroll on the right.
# 4. Subclass the left and look for EN_VSCROLL.  This only
# takes a click on the Desaware subclasser.
# 5. I recommend using 'POST-DEFAULT' processing for this
# application so that the scroll bar has a chance to update
# the left text box before the subclass function is called.
# 6. Add the following function
#
# Private Sub SubClassTxtScroll_WndMessage(wnd As Long, Msg
# As Long, wp As Long, lp As Long, retval As Long, nodef As
# Integer)
#
#     Dim sts As Long
#     Dim lTopLineLeft As Long
#     Dim lTopLineRight As Long
#     Dim lDifference As Long
#
#     ' Get the line numbers
#     lTopLineLeft = SendMessage(Me.txtTerm(0).hWnd,
# EM_GETFIRSTVISIBLELINE, 0, 0)
#     lTopLineRight = SendMessage(Me.txtTerm(1).hWnd,
# EM_GETFIRSTVISIBLELINE, 0, 0)
#
#     ' determine the difference between the lines
#     lDifference = lTopLineLeft - lTopLineRight
#     If (lDifference = 0) Then
#         GoTo exitPt
#     End If
#
#     ' move the right text box so that the top lines match
#     sts = SendMessage(Me.txtTerm(1).hWnd, EM_LINESCROLL,
# 0, lDifference)
#
# exitPt:
# End Sub
#
# Best regards,
#
# Chuck



Sun, 31 Jul 2005 08:02:09 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Building A Scroll Bar / Scroll Bar Colors

2. scroll bars on single form (non-MDI) window?

3. Turning off scroll bars in VB5

4. Scroll without scroll bar - VB.net

5. vertical scroll bars to scroll a maximized form??

6. Scrolling data with Vertical scroll bar ?

7. Scrolling without scroll bars (question)

8. Turning off scrolling within simple textbox

9. contents won't scroll when scroll bar is dragged

10. Scroll bar keeps scrolling within Flexgrid

11. listbox and scroll vertical scroll bar

12. Scroll text off top of TextBox screen?

 

 
Powered by phpBB® Forum Software