Hi,
Has anybody got any idea as to how I can find out the current X,Y positions of a cursor in a richtextbox.
Thanks in advance
Shaun
Printable View
Hi,
Has anybody got any idea as to how I can find out the current X,Y positions of a cursor in a richtextbox.
Thanks in advance
Shaun
Shaun,
I just tried this code, and it tells you how many characters from the beginning the cursor is currently sitting at, the value gets stored in Endselect.
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 Const EM_GETSEL = &HB0
Private Sub Command1_Click()
Dim StartSelect, Endselect As Long
SendMessage RichTextBox1.hwnd, EM_GETSEL, StartSelect, Endselect
End Sub
Try it, see what you think...
Hi crispin,
Thanks for that, but it's not really what I'm looking for.
With your example, If the user selects a different font then, yes, the position in characters will stay the same but the cursor may be in a totally different place dependant on the font width.
I have tried using the GetCursorPos API without much success. It seems to be returning all sorts of different values! :mad:
Has anyone else got any ideas on how to get the X,Y position of the cursor in a RichTextBox???
Thanks
Shaun
Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Dim posX As POINTAPI
Dim iResult
iResult = GetCaretPos(posX)
MsgBox "X = " & posX.x & " Y = " & posX.y
End Sub
I think this works...(you are trying to get the flashing cursor position and not the mouse cursor position aren't you? - otherwise i'm barking up the wrong tree completely
:eek:
That's the one ;)
Cheers for your help
Shaun