VB6 RTB set first visible line

Posted on 2012-09-15
Last Modified: 2012-09-22
Dear Experts,

In VB6, how can I set the first visible line of a rich textbox? If it is on line 2 or greater, I want to set it to current first visible line minus 1.

Question by:ttobin333
    LVL 44

    Accepted Solution

    Option Explicit
    Private Declare Function SendMessage Lib "user32.dll" _
     Alias "SendMessageA" ( _
       ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       ByRef lParam As Any) As Long
    Const EM_LINESCROLL = &HB6
    Private Sub Command1_Click()
    Dim FirstVisibleLine As Long
    FirstVisibleLine = SendMessage(RichTextBox1.hwnd, EM_GETFIRSTVISIBLELINE, 0, ByVal 0&)
    If FirstVisibleLine > 1 Then ' lines are zero based
        SendMessage RichTextBox1.hwnd, EM_LINESCROLL, 0, ByVal -1
    End If
    End Sub

    Open in new window


    Author Closing Comment

    LVL 44

    Expert Comment

    by:Martin Liss
    You're welcome and I'm glad I was able to help.

    My profile contains links to some articles I've written that may interest you.
    Marty - MVP 2009 to 2012

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    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…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 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