# Thanks your help, I have another method for this problem ! (有兴趣请入内)

Posted by Albert on August 21, 1999 at 11:30:13:

In Reply to: Re: 请问: 如何得知 目前由标是停在 TextBox 的第几行 ? (无内文) Thanks much !!! posted by 小琳 on August 20, 1999 at 20:33:36:

我参考 http://www.hosp.ncku.edu.tw/~cww/ 中的程式

Option Explicit
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

' 以上加在 .bas 档
'============================================

Const EM_GETLINE = &HC4
Const EM_GETLINECOUNT = &HBA
Const EM_LINEFROMCHAR = &HC9
Const EM_GETSEL = &HB0
Const EM_LINEINDEX = &HBB

Public Function GetLinePos(Text1 As TextBox)
Dim lcnt As Long
Dim i As Long
Dim j As Long

i = SendMessage(Text1.hwnd, EM_GETSEL, wParam, lParam)
j = i / 2 ^ 16 '取得目前 Caret 所在前面有多少个byte
GetLinePos = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, j, 0) '取得前面有多少行
End Function

Follow Ups: