Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Position Within A Text Field

Status
Not open for further replies.

skuhlman

Programmer
Jun 10, 2002
260
US
Okay, I feel like I'm missing something very obvious here. Is there a way to know the position of your cursor within a text field. I've explored the SelText, SelLength, and SelStart properties, but they don't realy seem to be helpful. What I'm really after is... In a 30 characther field (select all on entry) as they type, mouse-click, and cursor around, where is the cursor sitting when they tab out of the field?
 
Hi skuhlman,

Normally, SelStart will give the position of the cursor. However, you said that you want the position "after they tab out of the field". The answer is: Nowhere. If the field does not have focus, there is no cursor in it.

Mike


Mike Lewis
Edinburgh, Scotland
 
After I leave the field is when I need to know, but what I need to know is where it was last prior to leaving the field. I've figured out that my problem with the SelStart property was that when I was displaying it for debuging purposes it was in the KeyPress event which showed values for the property PRIOR to the KeyPress instead of AFTER the keypress.
 
So then you should be able to set a form variable in you KeyPress event and query it in the LostFocus event.


Dave S.
[cheers]
 
It sounds like you need to put code in the InteractiveChange to write the value of SelStart to a custom property of your base textbox class. Then, in the LostFocus, read the value of that property.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike,

Wouldn't that require you to edit the field, in order for the interactivechange event to be fired?

All you have to do is read the selstart property in the lostfocus event - it remains available even when the cursor isn't there any more...

Good luck skuhlman!



Regards

Griff
Keep [Smile]ing
 
Griff,

Wouldn't that require you to edit the field, in order for the interactivechange event to be fired?

Of course. I was just trying to catch you out <g>.

Maybe I should've said to use the KeyPress event.

All you have to do is read the selstart property in the lostfocus event - it remains available even when the cursor isn't there any more...

Hmm. I thought that was skuhlman's original problem. I must admit that I haven't tried this myself.

Mike


Mike Lewis
Edinburgh, Scotland
 
Hi Mike,

My response was partly tongue in cheek... but I think the selstart will work.

have a nice weekend.



Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top