• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

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?
0
kainashi
Asked:
kainashi
3 Solutions
 
Ryan ChongCommented:
You mean the Text1.SelStart ??
0
 
FischermaenCommented:
You can place the cursor with text1.SelStart = <Position> and text1.SelLength = 0
0
 
irfanazamCommented:
this function will give you the line number of current character or where the cursor is

call function like this

GetCurrentLine Text1.Hwnd

Public Function GetCurrentLine(ByVal hwnd As Long) As Long
GetCurrentLine = SendMessage(hwnd, EM_LINEFROMCHAR, -1, 0)
End Function

I will provide code for other features you want.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
irfanazamCommented:
hi here are 2 functions
'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
0
 
CleanupPingCommented:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Split points between: ryancys and Fischermaen and irfanazam

DanRollins -- EE database cleanup volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now