Results 1 to 2 of 2

Thread: Display Line numbers in Richtextbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    127
    Dear, all I have been trying to display the line numbers in a richtextbox, but up to know without any success, can you help.

    Many thanks
    ASPWIZARD

    http://www.aspwizard.co.uk

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    <code.Serge posted this some time back.

    'adding line numbrs to the front of text in a rich text box

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Const EM_GETLINE = &HC4
    Private Const EM_GETLINECOUNT = &HBA
    Private Const EM_LINEINDEX = &HBB
    Private Const EM_LINELENGTH = &HC1

    Private Sub Command1_Click()
    Dim lngCount As Long
    Dim lngLineIndex As Long
    Dim lngLength As Long
    Dim strBuffer As String
    Dim strRichText As String
    Dim i As Integer

    'Get Line count
    lngCount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0)

    With RichTextBox1
    For i = 0 To lngCount - 1
    'Get line index
    lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, i, 0)
    'get line length
    lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0)
    'resize buffer
    strBuffer = Space(lngLength)
    'get line text
    Call SendMessageStr(.hwnd, EM_GETLINE, i, ByVal strBuffer)
    'Number each line
    strRichText = strRichText & CStr(i + 1) & " " & strBuffer & vbCrLf
    Next
    'rewrite numbered text in RichTextBox
    .Text = strRichText
    End With

    End Sub

    Private Sub Form_Load()
    With RichTextBox1
    .Text = "line one" & vbCrLf
    .Text = .Text & "line two" & vbCrLf
    .Text = .Text & "line three"
    End With
    End Sub
    [/code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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