tags:

views:

513

answers:

3

Hi, There is a way to keep the scroll on bottom for a multi line textbox?

Something like in the vb6

txtfoo.selstart=len(txtfoo.text)

I'm trying with txtfoo.selectionstart=txtfoo.text.length without success.

Regards.

+3  A: 

Ok, I found that the solution is to use txtfoo.AppendText instead of txtfoo.text+="something"

MazarD
+1  A: 

The other solution is to use:

txtfoo.Text += "something";
txtfoo.SelectionStart = txtfoo.Text.Length;
txtfoo.ScrollToCaret();
Matthew Scharley
A: 

Interesting question. I'm guessing that you are trying to select the text via form load? I can't get it working on form load, but I can on form click. Wierd. :)

Public Class Form1

    Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        ScrollTextbox()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ScrollTextbox()
    End Sub

    Private Sub ScrollTextbox()
        TextBox1.SelectionStart = TextBox1.TextLength
        TextBox1.ScrollToCaret()
    End Sub

End Class

If it is completely necessary, you could use a timer.

RodgerB
I'd guess it has something to do with the form not being properly initialised yet in the load handler. Try putting a call to this.Show() first, should clear up any issues.
Matthew Scharley