Solved

Vscrollbar in MULTILINE TEXTBOX

Posted on 1998-02-09
3
349 Views
Last Modified: 2008-02-01
I have two multiline text boxes. One text box contains text
on seeing these text i want to type the text in another text
box. As i type down, vertical scroll bar scrolls in the text
box i type, So at the same time the Vscroll bar in the source
text box should also scroll. How make the two vscrollbar scroll simultaneously and equally?
0
Comment
Question by:geostp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 9

Accepted Solution

by:
cymbolic earned 50 total points
ID: 1456738
You can control scrolling of a textbox control using Windows Messaging - see below:
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1456739
32bit:
*********first, some declares***************

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function SendMessageBynum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SendMessageBystring Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hDC As Long, lpMetrics As TEXTMETRIC) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long

Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
End Type

Type TEXTMETRIC
        tmHeight As Long
        tmAscent As Long
        tmDescent As Long
        tmInternalLeading As Long
        tmExternalLeading As Long
        tmAveCharWidth As Long
        tmMaxCharWidth As Long
        tmWeight As Long
        tmOverhang As Long
        tmDigitizedAspectX As Long
        tmDigitizedAspectY As Long
        tmFirstChar As Byte
        tmLastChar As Byte
        tmDefaultChar As Byte
        tmBreakChar As Byte
        tmItalic As Byte
        tmUnderlined As Byte
        tmStruckOut As Byte
        tmPitchAndFamily As Byte
        tmCharSet As Byte
End Type


Private Function GetVisibleLines%()
    Dim rc As RECT
    Dim hDC&
    Dim lfont&, oldfont&
    Dim di&
    Dim tm As TEXTMETRIC

    ' Get the formatting rectangle - this describes the

    ' rectangle in the control in which text is placed.
    lc% = SendMessage(Text1.hWnd, EM_GETRECT, Ø, rc)

    ' Get a handle to the logical font used by the control.
    ' The VB font properties are accurately reflected by
    ' this logical font.
    lfont = SendMessageBynum(Text1.hWnd, WM_GETFONT, Ø, Ø&)
   
    ' Get a device context to the text control.
    hDC = GetDC(Text1.hWnd)

    ' Select in the logical font to obtain the exact font
    ' metrics.

    If lfont <> Ø Then oldfont = SelectObject(hDC, lfont)

    di = GetTextMetrics(hDC, tm)
    ' Select out the logical font
    If lfont <> Ø Then lfont = SelectObject(hDC, oldfont)

    ' The lines depend on the formatting rectangle and font height
    GetVisibleLines% = (rc.bottom - rc.top) / tm.tmHeight

    ' Release the device context when done.
    di = ReleaseDC(Text1.hWnd, hDC)
End Function

*******then, to scroll*************
    ' Get the number of the first and last visible line
    firstvisible% = SendMessageBynum(Text1.hWnd, EM_GETFIRSTVISIBLELINE, Ø, Ø&)
    lastvisible% = GetVisibleLines%() + firstvisible% - 1
   
    ' Scroll it into view if necessary
    If (VScroll1.value < firstvisible%) Then
        dl& = SendMessageBynum(Text1.hWnd, EM_LINESCROLL, Ø, CLng(VScroll1.value - firstvisible%))
    End If
    If (VScroll1.value > lastvisible%) Then
        dl& = SendMessageBynum(Text1.hWnd, EM_LINESCROLL, Ø, CLng(VScroll1.value - lastvisible%))

    End If

***********other interesting things you can do *************
'
' Determine the number of the first line visible in the text control
'
Private Sub MenuFirstVisible_Click()
    Dim lc%
    lc% = SendMessageBynum(Text1.hWnd, EM_GETFIRSTVISIBLELINE, Ø, Ø&)
    LabelResult.Caption = "Line" + Str$(lc%) + " at top"

End Sub

'
' Determine the number of lines of text in the text control

'
Private Sub MenuLineCount_Click()
    Dim lc%
    lc% = SendMessageBynum(Text1.hWnd, EM_GETLINECOUNT, Ø, Ø&)
    LabelResult.Caption = Str$(lc%) + " lines"
End Sub

'
' Determine the number of visibile lines in the text control.
'
Private Sub MenuLinesVisible_Click()
    LabelResult.Caption = Str$(GetVisibleLines()) + " lines visible"
End Sub

'
' Determine the start and end position of the current selection
'
Private Sub MenuSelected_Click()
    Dim ls&

    ls& = SendMessageBynum&(Text1.hWnd, EM_GETSEL, Ø, Ø&)

    LabelResult.Caption = "Chars" + Str$(CInt(ls& And &HFFFF&)) + " to" + Str$(CInt(ls& / &H1ØØØØ))


End Sub

*********for a more complete description, it's worth your money to buy "Visual Basic and the Win32 API" by Dan Appleman
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1456740
Oops! here are the constants you'll need (plus some others):
Public Const EM_GETSEL = &HB0
Public Const EM_SETSEL = &HB1
Public Const EM_GETRECT = &HB2
Public Const EM_SETRECT = &HB3
Public Const EM_SETRECTNP = &HB4
Public Const EM_SCROLL = &HB5
Public Const EM_LINESCROLL = &HB6
Public Const EM_SCROLLCARET = &HB7
Public Const EM_GETMODIFY = &HB8
Public Const EM_SETMODIFY = &HB9
Public Const EM_GETLINECOUNT = &HBA
Public Const EM_LINEINDEX = &HBB
Public Const EM_SETHANDLE = &HBC
Public Const EM_GETHANDLE = &HBD
Public Const EM_GETTHUMB = &HBE
Public Const EM_LINELENGTH = &HC1
Public Const EM_REPLACESEL = &HC2
Public Const EM_GETLINE = &HC4
Public Const EM_LIMITTEXT = &HC5
Public Const EM_CANUNDO = &HC6
Public Const EM_UNDO = &HC7
Public Const EM_FMTLINES = &HC8
Public Const EM_LINEFROMCHAR = &HC9
Public Const EM_SETTABSTOPS = &HCB
Public Const EM_SETPASSWORDCHAR = &HCC
Public Const EM_EMPTYUNDOBUFFER = &HCD
Public Const EM_GETFIRSTVISIBLELINE = &HCE
Public Const EM_SETREADONLY = &HCF
Public Const EM_SETWORDBREAKPROC = &HD0
Public Const EM_GETWORDBREAKPROC = &HD1
Public Const EM_GETPASSWORDCHAR = &HD2
Public Const WM_GETFONT = &H31

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

689 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