Character Position in TextBox

A

Agnes

In my Textbox, User will input a date e.g "2004-12-06"
How can I check the curosr position if the user use mouse or arrow to move
the cursor position in the textbox ?
e.g "2004-12-06" if user move the cursor and delete "2" . like this
"2004-1-06"
I need to get know the position just after "1" .... '2004-1"
I need to get the result "6" ,
Does anyone understand my problem ?? Thanks a lot
 
G

Galcho

Hello Agnes,
I think you need SelectionStart property of TextBox control
SelectionLenght will show you how many characters are selected - 0 when you
have no seelction
when SelectionLenght is 0 you can check SelectionStart to get possition
of carret

regards

Galin Iliev
MCSD, MCAD.NET
 
H

Herfried K. Wagner [MVP]

Agnes said:
In my Textbox, User will input a date e.g "2004-12-06"
How can I check the curosr position if the user use mouse or arrow to move
the cursor position in the textbox ?
e.g "2004-12-06" if user move the cursor and delete "2" . like this
"2004-1-06"
I need to get know the position just after "1" .... '2004-1"
I need to get the result "6" ,
Does anyone understand my problem ?? Thanks a lot

Take a look at the 'SelectionStart'/'SelectionLength'/'SelectedText'
properties. You can use the 'Mid' function or 'String.Substring' to extract
a part of the text.
 

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