Solved

Vscrollbar in MULTILINE TEXTBOX

Posted on 1998-02-09
3
342 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 82
Best way to parse out a json string in VB6? 10 112
passing a value with stream reader AFTER a ";" 3 58
Hide vba in gp 7 83
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now