Cursor at the end of text

  • Thread starter Thread starter Beebs
  • Start date Start date
B

Beebs

How can I place the cursor at the end of the text in a textbox when
the user presses a button?
 
textbox.SelectionLength = 0;
textbox.SelectionStart = textbox.TextLength-1;
textbox.ScrollToCaret();

should do it
 
Thanks for the help, but I'm getting

An unhandled exception of type 'System.ArgumentException' occurred in
System.Windows.Forms.dll

on this line (I'm using VB .NET btw):

textbox.SelectionStart = textbox.TextLength - 1

Any suggestions?
 
Sure, if the textbox is empty, then TextLength - 1 evaluates to -1 and
SelectionStart can't be < 0. You have to check for that case.

-Chris
 
Back
Top