Snippet
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_SETSEL = &HB1
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Sub SelectLine(ByRef lineNum As Long, ByRef rtb As System.Windows.Forms.RichTextBox)
Dim _start As Long
Dim _end As Long
Dim numLines As Long
With rtb
'Get the line count in the RichTextBox
numLines = SendMessage(.handle, EM_GETLINECOUNT, 0, 0&)
'Make sure the line number provided isnt greater
'than the number of lines in the box, if
'so then exit
If lineNum > numLines - 1 Then Exit Sub
'Get the beginning of the line
_start = SendMessage(.handle, EM_LINEINDEX, lineNum, 0&)
'Get the end of the line
_end = SendMessage(.handle, EM_LINEINDEX, lineNum + 1, 0&)
'Set focus to the control
.Focus()
'Highlight the desired row
Call SendMessage(.handle, EM_SETSEL, _start, _end)
End With
End Sub
Copy & Paste
|