Cursor position

  • Thread starter Thread starter JonWayn
  • Start date Start date
J

JonWayn

I am trying to record the position of the cursor within a textbox which I
achieve by using the SelStart property of the textbox. However, if I
double-click in the middle of some word to highlight the entire word, the
SelStart property returns the position of the characyer in the middle of the
text that was clicked on. I have tried reading this prop in the Click,
MouseUp, and Double-Click events - all return the same anamalous result. I am
doing this as part of a delete routine I want to trigger from the click of a
main form button. Any idea on where I need to record this property in order
to get the desired reading?
 
JonWayn said:
I am trying to record the position of the cursor within a textbox which I
achieve by using the SelStart property of the textbox. However, if I
double-click in the middle of some word to highlight the entire word, the
SelStart property returns the position of the characyer in the middle of the
text that was clicked on. I have tried reading this prop in the Click,
MouseUp, and Double-Click events - all return the same anamalous result. I am
doing this as part of a delete routine I want to trigger from the click of a
main form button. Any idea on where I need to record this property in order
to get the desired reading?

As you've found, SelStart is set to the point of the click.
So you will have to calculate the position if you want
something different. If all your "words" are preceeded by a
space, then you could use something like:

If IsNull(Me.Text0) Or Me.Text0.SelStart = 0 Then
pos = Me.Text0.SelStart
Else
pos = InStrRev(Me.Text0, " ", Me.Text0.SelStart) + 1
End If
 
Back
Top