Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

Scrolling back up to the Top of a Textbox control

Hi, I'm using VB.NET2010, WinForms. I have a Form with a textbox, where I append some text to the textbox after parsing an external text file. That part works well.

However, once all the text is appended, the scroll-bar is all the way down at the bottom of the file. I'd like to have the scroll bar move to the top of the file, so the user doesn't have to scroll back up manually to begin viewing the file.

I tried  ScrollToCarrot(), but I'm not sure how to set the target "Carrot."

How would I do that or is there a better way?

Thanks,
Fulano
Avatar of miketonny
miketonny

try set focus first then use scrolltocaret()

 
      TextBox1.Focus()
        TextBox1.ScrollToCaret()

Open in new window

also, if that doesn't work for you,
use TextBox1.SelectionStart
Avatar of kaufmed
Try setting the SelectionStart:
this.textBox1.SelectionStart = 0;
this.textBox1.Focus();    // If necessary (e.g. user clicks button to scroll)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Heheh...

Of course, in VB, you'd use "Me", not "this"  : )
Avatar of Mr_Fulano

ASKER

Most accurate solution. It worked as is. Thanks