Textchanged event, controlling editor cursor position

A

Adriana Camargo

Hi

I have to change automatically the text inside a textbox.
I need to add thousand separator when I am writting in the textbox.
I am using TextChanged event and when I insert a new number, i have a
function that formats the complete text with thousand separator.

For example, if textbox1 content is 1,234 and i added a number 5 after
number 1, the result must be 15,234.

The problem is that I can not control editor curso position. Each time
TextChanged is called, the cursor places at the beginning of the
textbox.

I need to place the cursor at the last position where i write the new
number.

Any ideas?
 
G

Guest

Adriana said:
Hi

I have to change automatically the text inside a textbox.
I need to add thousand separator when I am writting in the textbox.
I am using TextChanged event and when I insert a new number, i have a
function that formats the complete text with thousand separator.

For example, if textbox1 content is 1,234 and i added a number 5 after
number 1, the result must be 15,234.

The problem is that I can not control editor curso position. Each time
TextChanged is called, the cursor places at the beginning of the
textbox.

I need to place the cursor at the last position where i write the new
number.

Any ideas?

Use the Textbox.SelectionStart and Textbox.SelectionLength properties.

Chris
 
A

Adris

But when i changed the text in the textbox, Textbox.SelectionStart is
always 0, and I can't retrieve the last one.


Adris Vb.net
 
G

Guest

Adris said:
But when i changed the text in the textbox, Textbox.SelectionStart is
always 0, and I can't retrieve the last one.


Adris Vb.net

you will have to save where it is in the keypress event before you let
them type.

Chris
 

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