Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,232 times

Related Categories

Get RichTextBox Status Information

This example demonstrates a simply way to get information from a RichTextBox that is often displayed in a status bar (ie number of lines, current line, column etc). This code uses API calls in some cases, and expects the RichTextBox to be called rtfMain.

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 Const EM_LINEINDEX = &HBB
Private Const EM_GETFIRSTVISIBLELINE = &HCE
Private Const EM_GETLINECOUNT = &HBA

Public Property Get LineCount() As Long
    LineCount = SendMessage(rtfMain.hwnd, EM_GETLINECOUNT, 0&, 0&)
End Property

Public Property Get GetFirstLineVisible() As Long
    GetFirstLineVisible = SendMessage(rtfMain.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&)
End Property

Public Property Get CurrentColumn() As Long
Dim lCurLine As Long
    ' Current Line
    lCurLine = 1 + rtfMain.GetLineFromChar(rtfMain.SelStart)
    ' Column
    CurrentColumn = SendMessage(rtfMain.hwnd, EM_LINEINDEX, ByVal lCurLine - 1, 0&)
    CurrentColumn = (rtfMain.SelStart) - CurrentColumn
End Property

Public Property Get CurrentLine() As Long
    CurrentLine = 1 + rtfMain.GetLineFromChar(rtfMain.SelStart)
End Property

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • finally

    Posted by cRuLo on 20 Jun 2003

    i have been looking for something like this for the longest. thanks man, nice code.