回复 8楼 wds1
2个Timer是为了演示 TEXT与RichTextBox的区别
只放在Change事件中,没办法响应滚动条事件,
'-----------------------------------------------
异常应该还是在这里,UBound(Split(RichTextBox2.Text, vbCrLf)) ,为什么会冲突还不清楚。
既然获取TEXT1没有问题的话,那么.......再加一个RichTextBox3同步中转再获取其行数,是不是就不会冲突了?
试了下,可行,基本上全搞定啦。
程序代码:
Private Declare Function FuckSendMessage 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
Private Sub RichTextBox2_Change()
RichTextBox3.Text = RichTextBox2.Text 'RichTextBox3.Text同步RichTextBox2
End Sub
Private Sub Timer1_Timer()
RichTextBox1.Text = ""
i = FuckSendMessage(RichTextBox2.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&) + 1 '取滚动条刻度值
For j = i To UBound(Split(RichTextBox3.Text, vbCrLf)) + 1 '获取RichTextBox3行数
RichTextBox1.Text = RichTextBox1.Text & j & vbCrLf
Next
End Sub