locked
Focus Cursor at end of Textbox Contents RRS feed

  • Question

  • Hi All - when i click a button i want the cursor to focus in a text box and at the end of any text that there maybe in the textbox - so the user can strat typing straight away.

     

    textbox1.focus()

     

    This currently only focuses at the begining of the textbox before all the text...

     

    is there a way?

    Thanks Poy

    Thursday, October 18, 2007 8:23 AM

Answers

  • Thanks Man - i actually got around it another way just this morning:

     

    txtJob.Focus()

    txtJob.SelectionStart = txtJob.TextLength

     

    but will definately keep your method handy for the next time..

    thanks for the input though.

    Poy.

    Monday, October 22, 2007 11:10 AM
  • Hi, Poy,

     

    Based on my understanding, you want to focus to the end of the string in your TextBox, don't you?

     

    A tricky way is to send a Right key after you focus on this TextBox.

    For example

     

    Code Block

                textBox1.Focus();

                SendKeys.Send("{Right}");

     

     

    More info

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

     

    Hope this helps,

    Regards

    Monday, October 22, 2007 3:00 AM

All replies

  • Hi, Poy,

     

    Based on my understanding, you want to focus to the end of the string in your TextBox, don't you?

     

    A tricky way is to send a Right key after you focus on this TextBox.

    For example

     

    Code Block

                textBox1.Focus();

                SendKeys.Send("{Right}");

     

     

    More info

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

     

    Hope this helps,

    Regards

    Monday, October 22, 2007 3:00 AM
  • Thanks Man - i actually got around it another way just this morning:

     

    txtJob.Focus()

    txtJob.SelectionStart = txtJob.TextLength

     

    but will definately keep your method handy for the next time..

    thanks for the input though.

    Poy.

    Monday, October 22, 2007 11:10 AM