Results 1 to 3 of 3

Thread: How to use a Scroll control on multiple textboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    1

    Question

    How does one use a Horizontoal Scroll control to change two textboxes simultaneously? If I output a database to a textbox, I want to put the fieldnames in one and the data in another.

    Then I want to scroll to see the stuff on the far edge and have both boxes scroll together, keeping the Fieldname aligned with the Data.

  2. #2
    Member simlee's Avatar
    Join Date
    Mar 2002
    Posts
    40

    No one's ever Cracked this

    I did a search for my current predicament and this post matched it perfectly - but D'oh! No response?

    Have we all failed?

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I'm pretty sure you'll need to subclass
    VB Code:
    1. '*************
    2. '* In a form *
    3. '*************
    4. Option Explicit
    5.  
    6. Private Sub Form_Load()
    7.    
    8.     Call InitText
    9.  
    10.     Call Hook(Text1.hwnd)
    11. End Sub
    12.  
    13. Private Sub Form_Unload(Cancel As Integer)
    14.     Call Unhook(Text1.hwnd)
    15. End Sub
    16.  
    17. Private Sub InitText()
    18. Dim x As Integer
    19.  
    20.     For x = 1 To 40
    21.         Text1.Text = Text1.Text & "Test" & vbCrLf
    22.     Next
    23.    
    24.     Text2.Text = Text1.Text
    25.  
    26. End Sub
    27.  
    28. '************************
    29. '* In a standard module *
    30. '************************
    31. Option Explicit
    32.  
    33. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
    34.                                                                             ByVal nIndex As Long, _
    35.                                                                             ByVal dwNewLong As Long) _
    36.                                                                             As Long
    37. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    38.                                                                               ByVal hwnd As Long, _
    39.                                                                               ByVal Msg As Long, _
    40.                                                                               ByVal wParam As Long, _
    41.                                                                               ByVal lParam As Long) _
    42.                                                                               As Long
    43. Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
    44.                                                                             ByVal wMsg As Long, _
    45.                                                                             ByVal wParam As Long, _
    46.                                                                             ByVal lParam As Long) _
    47.                                                                             As Long
    48. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    49.                                                                             ByVal wMsg As Long, _
    50.                                                                             ByVal wParam As Long, _
    51.                                                                             ByVal lParam As Long) _
    52.                                                                             As Long
    53.  
    54. Private Const GWL_WNDPROC = (-4)
    55. Private Const WM_VSCROLL = &H115
    56.  
    57. Private mPrevProc As Long
    58.  
    59. Public Sub Hook(ByVal hwnd As Long)
    60.     mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
    61. End Sub
    62.  
    63. Public Sub Unhook(ByVal hwnd As Long)
    64.  
    65.     Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc)
    66.     mPrevProc = 0&
    67.  
    68. End Sub
    69.  
    70. Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    71. On Error Resume Next
    72.  
    73.     If uMsg = WM_VSCROLL Then
    74.         Call SendMessageLong(Form1.Text2.hwnd, uMsg, wParam, lParam)
    75.     End If
    76.    
    77.     If mPrevProc Then
    78.         WndProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam)
    79.     Else
    80.         WndProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
    81.     End If
    82.  
    83. End Function

    Assumes a form called Form1, that has two textboxes (Text1 and Text2)

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width