根据http://www.程序,简化版
用得到1个picturebox,2个richtextbox
Private Declare Function SendMessageLong Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function SendMessageByRef Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageByLong 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_GETLINECOUNT = &HBA
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_GETFIRSTVISIBLELINE = &HCE
Public Function LineCount() As Long 'richtextbox总行数
LineCount = SendMessageByRef(Text2.hWnd, EM_GETLINECOUNT, 0&, 0&)
End Function
Public Function FirstVisibleLine() As Long 'richtextbox第一行可见行数
FirstVisibleLine = SendMessageByLong(Text2.hWnd, EM_GETFIRSTVISIBLELINE, 0, 0)
End Function
Private Sub Form_Initialize()
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height
Picture1.Top = 0
Picture1.Left = 0
Text1.Width = 500
Text1.Height = Screen.Height
Text1.Top = 0
Text1.Left = 0
Text2.Width = Screen.Width - 500
Text2.Height = Screen.Height
Text2.Top = 0
Text2.Left = 500
End Sub
Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer) '键盘事件
Call row
End Sub
Private Sub Text2_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) '鼠标事件
Call row
End Sub
Private Sub Text2_SelChange() 'richtext文本标尺更改
Call row
End Sub
Private Sub row
lcount = LineCount '行总数
lcurrent = SendMessageLong(Text2.hWnd, EM_LINEFROMCHAR, Text2.SelStart, 0&) '当前行【0开始】
lline = FirstVisibleLine '最高可见行
Text1.Text = ""
For i = lline + 1 To lcount
Text1.Text = Text1.Text & Str(i) & vbCrLf
Next
End Sub
[此贴子已经被作者于2018-6-12 05:38编辑过]