Caret in textbox

  • Thread starter Thread starter P
  • Start date Start date
P

P

Is there a way to get the caret placed at the end of the text in a textbox
when it recieves focus. What I want to do is trap a certain key and insert a
charachter to a textbox and focus it. But the caret appears at the beginning
of the string. Not quite what I was looking for.

Advice?

<P>
 
this.TextBox1.SelectionStart = this.TextBox1.Text.Length;

Should do it for you.

If you want to insert a character at the position of the caret this should
work:

int pos = TextBox1.SelectionStart;
TextBox1.Text = tBox.Text.Insert( pos, myChar );
TextBox1.SelectionStart = pos + 1;

/ Peter
 
You can place the carret wherever you want. To place it at the end use: this.textBox1.SelectionStart=this.textBox1.Text.Length; (you could write the following code in OnFocus event)
 
Hi,
try...
txtMyText.Focus
txtMyTest.SelectionStart = txtMyTest.TextLength

HTH

Pete
 
Back
Top