Get caret pos in TextBox

G

Guest

The documentation states that you can use the SelectionStart property of the
TextBox to get the position of the caret in the TextBox. Well, what if the
selection is BEFORE the caret?

Say you have the word “TEXT†and you want to select “EXâ€. There are 2 ways
you can do this.
You can click before the E and drag to the X so the caret is now sitting
after the X.
You can click after the X and drag to the E so the caret is now sitting
before the E.

In both cases the SelectionStart property has the value of 1 and the
SelectionLength has a value of 2, yet the caret is in two different places.
Using the SelectionStart property alone can’t always give you the correct
caret position.

How can one get the true caret position and be absolutely sure it’s correct?
 

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