Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21842

[VB6 - RichTextBox] - how can i get the cursor position?

$
0
0
i have these code for get the cursor position, but i get bad results:(
Code:

Private Sub CheckPosition()
    Dim start_pos As Long
    Dim end_pos As Long
    Dim row As Long
    Dim col As Long

    SendMessageReferenceParams _
        RichTextBox1.hwnd, EM_GETSEL, start_pos, end_pos

    row = SendMessage(RichTextBox1.hwnd, EM_LINEFROMCHAR, _
        start_pos, 0) + 1
    col = start_pos - SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, _
        -1, 0) + 1

    Label1.Caption = "(" & Format$(row) & ", " & _
        Format$(col) & ")"
End Sub

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    Call CheckPosition
End Sub

these code do the job, but sometimes i don't get the actual position:(
(when moves to next line, the X position isn't correct, seems that new line is like be 2 characters instead 1.. something like)
can anyone advice me?

Viewing all articles
Browse latest Browse all 21842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>