Find the cursor position in a textbox

N

Neil Robbins

Could anyone suggest a way in which I could find the position of the cursor
within a textbox.

I want to evaluate every keypress made within the textbox in order to
validate it but in order to do this I need to know where the cursor is when
the key is pressed. So far I can't see how I could do this.

Any help would be very much appreciated,

Neil R.
 
N

Neil Robbins

Hi Ken,

Thanks for the response, unfortunately I think that perhaps I should have
been a little more specific.

I need to to know the location of the text cursor, not the mouse cursor. So
if there are 10 characters allowed in the textbox and the user has entered a
string of 6 characters but has gone back to edit the third character I need
to know that it is the third character that is being edited and not the
second (or any other) character.

I hope that this clarifies things a little.

Any further help would be greatly appreciated.

Neil R.
 
H

Herfried K. Wagner [MVP]

* "Neil Robbins said:
Thanks for the response, unfortunately I think that perhaps I should have
been a little more specific.

I need to to know the location of the text cursor, not the mouse cursor. So

The text cursor is called caret.
if there are 10 characters allowed in the textbox and the user has entered a
string of 6 characters but has gone back to edit the third character I need
to know that it is the third character that is being edited and not the
second (or any other) character.

Maybe you are looking for the control's 'SelectionStart' property?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top