kainashi
asked on
VB6: TextBox: advanced topic
Is there any way to control, via VB code, the position of the keyboard cursor in a TextBox control?
I mean, can I get its (row,col) current position, and set it to a particular (row,col) value? What functions/subs do I use?
I mean, can I get its (row,col) current position, and set it to a particular (row,col) value? What functions/subs do I use?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
kainashi:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
Moderator, my recommended disposition is:
Split points between: ryancys and Fischermaen and irfanazam
DanRollins -- EE database cleanup volunteer
Split points between: ryancys and Fischermaen and irfanazam
DanRollins -- EE database cleanup volunteer
'This will give you the line number of cursor position
'in TextBox Text1.
CurLine = GetCurrentLine(Text1)
'This will give you the Column number of cursor position
'in TextBox Text1.
CurCol = GetCurrentCol(Text1)
''''''''''''''''''''''''''
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
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
Function GetCurrentCol(tbox As TextBox) As Long
Dim CurLine As Long
Dim TotalLines As Long
Dim t As Long
CurLine = SendMessage(tbox.hwnd, EM_LINEFROMCHAR, -1, 0)
t = 0
If CurLine > 0 Then
CurCol = SendMessage(tbox.hwnd, EM_LINEINDEX, CurLine, 0)
t = CurCol
End If
GetCurrentCol = tbox.SelStart - t + 1
End Function
Public Function GetCurrentLine(tbox As TextBox) As Long
GetCurrentLine = SendMessage(tbox.hwnd, EM_LINEFROMCHAR, -1, 0) + 1
End Function
Hope it will solve your problem
I soon will post the routines to set cursor position in a text box