The .Net way
although the above works its not the .net way:) you lose portability plus your making calls to unmanaged code on the other hand her is a nice snippet you can use, just inherit a richtextbox and add the following
Private Const EM_LINELENGTH = &HC1
Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETFIRSTVISIBLELINE = &HCE
Private Const EM_LINESCROLL = &HB6
Private Const EM_POSFROMCHAR = &HD6
Private Const EM_GETSEL = &HB0
Private Const EM_SETSEL = &HB1
Private Const EM_CANUNDO = &HC6
Private Const EM_SETTEXTEX = (WM_USER + 97)
Private Const EM_GETTEXTEX = (WM_USER + 94)
Private Const EM_GETSELTEXT = (WM_USER + 62)
Private Const EM_REPLACESEL = &HC2
Private Const EM_STREAMOUT = (WM_USER + 74)
Private Const EM_STREAMIN = (WM_USER + 73)
Private Const EM_SCROLLCARET = &HB7
Private Const EM_FINDTEXTEX = (WM_USER + 79)
Private Const EM_CHARFROMPOS = &HD7
Private Const EM_GETRECT = &HB2
Private Const EM_SETRECT = &HB3
Public Function GetLine(ByVal charindex As Integer) As Integer
Dim m As Message = Message.Create(Me.Handle, EM_LINEFROMCHAR, New IntPtr(charindex), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetLineStart(ByVal line As Integer) As Integer
Dim m As Message = Message.Create(Me.Handle, EM_LINEINDEX, New IntPtr(line), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetLineLength(ByVal line As Integer) As Integer
Dim m As Message = Message.Create(Me.Handle, EM_LINELENGTH, New IntPtr(line), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetLineCount() As Integer
Dim m As Message = Message.Create(Me.Handle, EM_GETLINECOUNT, New IntPtr(0), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetCurrentLineStart() As Integer
Dim m As Message = Message.Create(Me.Handle, EM_LINEINDEX, New IntPtr(-1), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetCurrentLine() As Integer
Dim m As Message = Message.Create(Me.Handle, EM_LINEFROMCHAR, New IntPtr(-1), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetFirstVisibleLine() As Integer
Dim m As Message = Message.Create(Me.Handle, EM_GETFIRSTVISIBLELINE, New IntPtr(0), New IntPtr(0))
MyBase.WndProc(m)
Return m.Result.ToInt32
End Function
Public Function GetLastVisibleLine() As Integer
Return Me.GetLine(Me.GetCharIndexFromPosition(New Point(0, Me.Height - iHortBorderWidth)))
End Function
i know some of the above are duplicated from what it already has for example getlinefromcharindex, but do a performance test on mine vs the control its 4-5 times faster go figure....
-Xposure