VB获取richtextbox光标所在的位置

在网上找到如下代码,但是不清楚怎样将光标的位置显示在一个TextBox里,请高手指点,谢谢'支持中文,一个汉字算一列ConstWM_USER=&H400ConstEM_E... 在网上找到如下代码,但是不清楚怎样将光标的位置显示在一个TextBox里,请高手指点,谢谢
'支持中文,一个汉字算一列
Const WM_USER = &H400
Const EM_EXGETSEL = WM_USER + 52
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
Const EM_GETSEL = &HB0
Private Type CHARRANGE
cpMin As Long
cpMax As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Function GetCurPos(ByRef TextControl As Control) As POINTAPI
Dim LineIndex As Long
Dim SelRange As CHARRANGE
Dim TempStr As String
Dim TempArray() As Byte
Dim CurRow As Long
Dim CurPos As POINTAPI
TempArray = StrConv(TextControl.Text, vbFromUnicode)
Call SendMessage(TextControl.hWnd, EM_EXGETSEL, 0, SelRange)
CurRow = SendMessage(TextControl.hWnd, EM_LINEFROMCHAR, SelRange.cpMin, 0)
LineIndex = SendMessage(TextControl.hWnd, EM_LINEINDEX, CurRow, 0)
If SelRange.cpMin = LineIndex Then
GetCurPos.x = 1
Else
TempStr = String(SelRange.cpMin - LineIndex, 13)
CopyMemory ByVal StrPtr(TempStr), ByVal StrPtr(TempArray) + LineIndex, SelRange.cpMin - LineIndex
TempArray = TempStr
ReDim Preserve TempArray(SelRange.cpMin - LineIndex - 1)
TempStr = StrConv(TempArray, vbUnicode)
GetCurPos.x = Len(TempStr) + 1
End If
GetCurPos.y = CurRow + 1
End Function
展开
 我来答
chinaboyzyq
2014-04-14 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:3256万
展开全部
。。。

。。。

text1.text=GetCurPos.x & "," & GetCurPos.y

End Function

没测试……,你自己测试一下。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式