how to set the cursor position in a text box control.
Printable View
how to set the cursor position in a text box control.
If you mean to set the focus to the text box then use
Code:Textboxname.SetFocus
But if you mean the mouse cursor then
Code:Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
'somethin like this
Dim r as RECT
GetWindowRect text1.hwnd,r
SetCursorPos r.left + (text1.width /2),r.top + (text1.height/2)
no to change the cursor position within the textbox
You can use
Code:Private Sub Form_Click()
SendKeys "{RIGHT}", True
End Sub
Or just change the SelStart property of the TextBox.
Code:Text1.SelStart = 10