'在form中放一个textBox两个labelConst EM_GETSEL = &HB0Const EM_LINEFROMCHAR = &HC9Const EM_LINEINDEX = &HBBPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _lParam As Any) As LongPublic Sub GetCaretPos(ByVal hwnd5 As Long, LineNo As Long, ColNo As Long)Dim i As Long, j As LongDim lParam As Long, wParam As LongDim k As Longi = SendMessage(hwnd5, EM_GETSEL, wParam, lParam)j = i / 2 ^ 16 '取得目前Caret所在前面有多少个byteLineNo = SendMessage(hwnd5, EM_LINEFROMCHAR, j, 0) '取得前面有多少行LineNo = LineNo + 1k = SendMessage(hwnd5, EM_LINEINDEX, -1, 0)'取得目前caret所在行前面有多少个byteColNo = j - k + 1End SubPrivate Sub Form_Load()Dim LineNo As Long, ColNo As LongCall GetCaretPos(Text1.hwnd, LineNo, ColNo)Label1.Caption = LineNoLabel2.Caption = ColNoEnd SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)Dim LineNo As Long, ColNo As LongCall GetCaretPos(Text1.hwnd, LineNo, ColNo)Label1.Caption = LineNoLabel2.Caption = ColNoEnd SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim LineNo As Long, ColNo As LongCall GetCaretPos(Text1.hwnd, LineNo, ColNo)Label1.Caption = LineNoLabel2.Caption = ColNoEnd Sub(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)