1,451
社区成员
发帖
与我相关
我的任务
分享
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
Const EM_GETFIRSTVISIBLELINE = &HCE
Const EM_LINEFROMCHAR = &HC9
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Public Function TopLineIndex(txtBox As RichTextBox) As Long
TopLineIndex = SendMessage(txtBox.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&)
End Function
Public Function GetLineFromChar(txtBox As RichTextBox, CharPos As Long) As Long
GetLineFromChar = SendMessage(txtBox.hwnd, EM_LINEFROMCHAR, CharPos, 0&)
End Function
Public Function LineCount(txtBox As RichTextBox) As Long
LineCount = SendMessage(txtBox.hwnd, EM_GETLINECOUNT, 0&, 0&)
End Function
Public Function ColIndex(txtBox As RichTextBox, Lops As Long) As Long
ColIndex = SendMessage(txtBox.hwnd, EM_LINEINDEX, Lops, 0)
End Function
Private Sub RichTextBox1_SelChange()
Dim lngLineIndex As Long
Dim lngLineCount As Long
Dim lngColIndex As Long
lngLineIndex = GetLineFromChar(RichTextBox1, RichTextBox1.SelStart)
lngLineCount = LineCount(RichTextBox1)
lngColIndex = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, lngLineIndex, 0)
Label1.Caption = "当前行号: " & lngLineIndex + 1
Label2.Caption = "当前位置: " & lngColIndex
Label3.Caption = "总行数: " & lngLineCount
End Sub