
Line and Column in RichTextBox
The following, written for a normal TextBox but will also works with a
RichTextBox if the references are changed appropriately (TextBox to
RichTextBox).
Paste this code in the (General)(Declarations) section of your Form for
single form use; or remove the Private keyword and place it into a BAS
Module (Project/AddModule from VB menu bar) for project wide scope:
****************BEGIN PASTE******************
Private Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Function CursorLine(TextBoxIn As TextBox) As Long
CursorLine = SendMessageLong(TextBoxIn.hwnd, &HC9, -1&, 0&) + 1
End Function
Function CursorColumn(TextBoxIn As TextBox) As Integer
CursorColumn = TextBoxIn.SelStart - _
SendMessageLong(TextBoxIn.hwnd, &HBB, -1, 0)
End Function
******************END PASTE******************
Rick
Quote:
> Hi!
> Is it possible to get line and column numbers of the cursor position in a
> RichTextBox control?
> Jan Petter