4

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.

MazarD
  • 2,759
  • 2
  • 22
  • 33
  • you have two solutions (yours and @monoxide's) that both seem to do what you want. I think you should accept one of them. – Hamish Smith Oct 05 '08 at 04:06
  • Except that you can't accept your own solution *shrugs* meh, I don't mind. – Matthew Scharley Oct 05 '08 at 11:25
  • Possible duplicate of [How do I automatically scroll to the bottom of a multiline text box?](http://stackoverflow.com/q/898307/10263). (Actually this question is older, but the other has more answers and more votes.) – Brian Rogers Oct 04 '13 at 20:24

3 Answers3

7

Ok, I found that the solution was to use

txtfoo.AppendText 

instead of

 txtfoo.text+="something"
Patrick D'Souza
  • 3,491
  • 2
  • 22
  • 39
MazarD
  • 2,759
  • 2
  • 22
  • 33
4

The other solution is to use:

txtfoo.Text += "something";
txtfoo.SelectionStart = txtfoo.Text.Length;
txtfoo.ScrollToCaret();
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
0

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
  • 8,608
  • 9
  • 36
  • 47
  • 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 Oct 08 '08 at 10:21