Let's say, you want to create a multi-line TextBox and put some text in it. And you want the TextBox to automatically scroll as you add the text. Nothing easier, just += new text to the Text property. You add the text, but you don't scroll it so the next hing you would probably try would be using SelectionStart() and ScrollToCaret() methods. It would work but also it would flicker a lot.
The right way is to assign new text to SelectedText property. This way you add text, scroll down and do that without flicker. Who would have thought? Not very intuitive, right?
textBox.Text = "First line.";
textBox.SelectionStart = textBox.TextLength;
for (int i = 0; i < 100; i++)
textBox.SelectedText = "Another line! #" + i.ToString() + Environment.NewLine;
All said goes for .NET 1.1. I checked 2.0 beta2 and it doesn't seem to have any better way for deailing with this problem.
[Update] Andrej pointed out, that there IS a better way to do this. The method is called AppendText() and it does just what I didn't find - appends the text and scrolls the scrollbar if necessary! Thanks, Andrej!
Internaly, AppendText() method does what I described above. "Luckily" there is an issue with text longer than 32767 bytes, so maybe I will not look like a complete jerk for posting this. To get arround the issue you can use my solution above or override the AppendText() method.