|
-
Jan 3rd, 2007, 07:11 AM
#1
Thread Starter
New Member
How to retreive cursor location from textbox
Hi
Try to create terminal emutalor for VMS.
Need to get cursor to follow the text in a text box and retreive cursor row and column.
thanks
Doug
-
Jan 3rd, 2007, 07:29 AM
#2
Re: How to retreive cursor location from textbox
Please mark you thread resolved using the Thread Tools as shown
-
Jan 3rd, 2007, 01:48 PM
#3
Thread Starter
New Member
Re: How to retreive cursor location from textbox
I would prefer the text box solution.
Because I an most familiar with it.
Doug
-
Jan 3rd, 2007, 02:20 PM
#4
Addicted Member
Re: How to retreive cursor location from textbox
Doug:
Cursor column is one thing, but cursor row depends entirely on how wide the text box is vs how large the font is, etc, etc.
The property Text1.SelStart can give the character location in the textbox, if that helps...?
-
Jan 4th, 2007, 08:01 AM
#5
Thread Starter
New Member
Re: How to retreive cursor location from textbox
If I had a page of text1.text 80 characters wide by 24 rows high.
How would I position the cursor at line/row 15 and character position 10?
thanks
Doug
-
Jan 4th, 2007, 09:03 AM
#6
Re: How to retreive cursor location from textbox
This function will return the position in pixels, not as row and column, so you might have to convert it somehow.
VB Code:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCaretPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
Private Sub Text1_Change()
Dim pt As POINTAPI
GetCaretPos pt
Me.Caption = pt.X & ", " & pt.Y
End Sub
-
Jan 4th, 2007, 09:31 AM
#7
Re: How to retreive cursor location from textbox
This might be closer to what you need
VB Code:
Private Const EM_LINEFROMCHAR As Long = &HC9
Private Const EM_LINEINDEX As Long = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Sub Text1_Change()
Dim Xpos As Long
Dim Ypos As Long
Xpos = Text1.SelStart - SendMessage(Text1.hwnd, EM_LINEINDEX, -1, 0&) + 1
Ypos = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, 0&) + 1
Label1.Caption = Xpos & ", " & Ypos
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|