TextBox.AppendText() not autoscrolling

.net, c#, textbox

Solution

Since the form isn't quite ready during the constructor and load event, I had to use a task to get it to scroll after it becomes ready:

Here is the method that gets invoked:

void scroll()
{
    this.Invoke(new MethodInvoker(delegate()
        {
            textBox1.SelectionStart = textBox1.Text.Length;
            textBox1.ScrollToCaret();
        }));
}

It gets invoked via this task placed in the load event:

Task task1 = new Task(new Action(scroll));
            task1.Start();

Problem

I tried the following to get my Textbox text to automatically scroll: The steps I am using are pretty trivial: - Drag textbox onto form. - Change textbox to be multiline. - Add vertical scroll. - Use AppendText() to add text to the textbox. The text does not automatically scroll, despite trying to solutions mentioned here: How do I automatically scroll to the bottom of a multiline text box? What could cause this and how do I fix it? UPDATE: If I create a button and use it to call AppendText() I get the desired behavior. However, if I try to call AppendText from the form's constructor or Load() event then I get the appended text but the TextBox does not scroll. This is NOT a duplicate question as I haven't seen anyone post this problem in the past.

Original source

Related problems