Home > C# > Line numbers in RichTextBox VB6

Line numbers in RichTextBox VB6


Option Explicit

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_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB

Private Sub GetLineNumber(rtb As RichTextBox)
Dim lines As Long
Dim i As Long
lines = SendMessage(rtb.hwnd, EM_GETLINECOUNT, 0&, 0&)
lblNumber.Caption = “”
For i = 1 To lines
lblNumber.Caption = lblNumber.Caption & CStr(i) & vbCrLf
Next i
End Sub

Private Sub GetCurrentLine(rtb As RichTextBox)
Dim lines As Long
Dim i, j As Long
Dim LN As Long
Dim curLine As Long

lines = SendMessage(rtb.hwnd, EM_GETLINECOUNT, 0&, 0&)
lblNumber.Caption = “”
For i = 1 To lines
If LN = SendMessage(rtb.hwnd, EM_LINEINDEX, i – 1, 0) Then Exit For
Next i
curLine = LN
For j = 1 To lines
If j = curLine Then
lblNumber.Caption = lblNumber.Caption & “* ” & CStr(j) & vbCrLf
Else
lblNumber.Caption = lblNumber.Caption & CStr(j) & vbCrLf
End If
Next j

End Sub
Private Sub rtb_Change()
GetCurrentLine rtb
End Sub

Private Sub UserControl_Initialize()
lblNumber.Height = rtb.Height
End Sub

Categories: C#
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: