Focus

R

Richard Grene

I set focus to a text box the data in the text box is highlited. When I
enter into the text box, whatever was there is replaced by what I entered.
How can I set this up so what I enter is appended to the text that is there.
I need to do this one character at a time. I'm using the KeyUp event to get
each new char entered.

Thanks,
Richard
 
C

Cor Ligthert

Hi Richard,

I use this for that
TextBox1.SelectionStart = TextBox1.Text.Length

I hope it helps for you?

Cor
 
H

Herfried K. Wagner [MVP]

* "Richard Grene said:
I set focus to a text box the data in the text box is highlited. When I
enter into the text box, whatever was there is replaced by what I entered.
How can I set this up so what I enter is appended to the text that is there.
I need to do this one character at a time. I'm using the KeyUp event to get
each new char entered.

Add a handler to the textbox's 'GotFocus' event and enter this code:

\\\
Dim t As TextBox = DirectCast(sender, TextBox)
t.Select(t.TextLength, 0)
///
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Does my simple code not works?

It works, but you didn't say where to place it. AFAIU the OP's post, he
wants the behavior when the control gets focus and the user types in
some text.
 
C

Cor Ligthert

Hi Herfried,
It works, but you didn't say where to place it. AFAIU the OP's post, he
wants the behavior when the control gets focus and the user types in
some text.

Will I copy this and place a message when you only send a link?

Although you did not read the message of the OP, because he stated for sure
I need to do this one character at a time. I'm using the KeyUp event to get
each new char entered.

For which what I sand works perfectly.

I find it a very awful procedure you did send. You said you have to add an
extra handler for the getFocus event as something extra (which will by the
way never fired)

I do not understand how that would work however maybe you can explain that.

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Will I copy this and place a message when you only send a link?

Although you did not read the message of the OP, because he stated for sure


For which what I sand works perfectly.

I find it a very awful procedure you did send. You said you have to add an
extra handler for the getFocus event as something extra (which will by the
way never fired)

I do not understand how that would work however maybe you can explain that.

When the control gets focus, the cursor is set after the last character
and not the whole text of the textbox is selected (which is the default
behavior). So tabbing to the textbox and pressing a key will /append/
it instead of /replacing/ the whole text in the textbox.
 
C

Cor Ligthert

Hi Herfried,
that.

When the control gets focus, the cursor is set after the last character
and not the whole text of the textbox is selected (which is the default
behavior). So tabbing to the textbox and pressing a key will /append/
it instead of /replacing/ the whole text in the textbox.
In my opinion exactly as the OP was asking for. However I can be wrong.

Cor
 

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