views:

362

answers:

3

I'm adding new logs line to a WinForms TextBox object, and this causes the textbox to scroll to the bottom. How can I prevent this and retain my current position? (a short code snippet would help)

A: 

Have you tried playing with the SelectionStart property?

Assaf Lavie
+1  A: 

SelectionStart didn't do what I want, for some reason. It got reset to 0. I found this post that answers what I wanted (which was to use a textbox as a log). The answer is TextBox.AppendText()

ripper234
A: 

Actually, AppendText() won't do what you want (try adding more text and at some point it all goes awry)

The answer actually lies within the Win32 API, and luckily for us, a fellow SO user has already implemented this behavior perfectly: http://stackoverflow.com/questions/1743448/auto-scrolling-text-box-uses-more-memory-than-expected-c-net-v3-5

ohadsc