下面是个简单易学的如何实现在TextBox中如何得知Caret所在位置教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!
【 tulaoshi.com - 编程语言 】
'在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://www.tulaoshi.com/bianchengyuyan/)
来源:http://www.tulaoshi.com/n/20160219/1608286.html
看过《如何实现在TextBox中如何得知Caret所在位置》的人还看了以下文章 更多>>