Solved

Vscrollbar in MULTILINE TEXTBOX

Posted on 1998-02-09
3
338 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
Comment Utility
You can control scrolling of a textbox control using Windows Messaging - see below:
0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

8 Experts available now in Live!

Get 1:1 Help Now