Text Box - Move to last line.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a multiline text box that is about 20 lines longs. I have a timer that writes a message to it ever minute. What I want is to have the last line of the text box always displayed. Right now, you have to scroll down to get to see what was last updated. How do I do it autmomatically with my code?

Drew
 
I haven't tested this, but I believe if you set the SelectionStart (or call
the Select() method) to the point where you want it to scroll and then call
the ScrollToCaret() method, that should do it.

Pete

Drew said:
I have a multiline text box that is about 20 lines longs. I have a timer
that writes a message to it ever minute. What I want is to have the last
line of the text box always displayed. Right now, you have to scroll down
to get to see what was last updated. How do I do it autmomatically with my
code?
 
I had to figure this out a long time ago, and finally found a solution:

myTextBox.SelectionStart = myTextBox.Text.Length;
myTextBox.ScrollToCaret();

(I acutally put this in the TextChanged event of the textbox, so I never
have to worry about it)

HTH
-Cliff

Drew said:
I have a multiline text box that is about 20 lines longs. I have a timer
that writes a message to it ever minute. What I want is to have the last
line of the text box always displayed. Right now, you have to scroll down
to get to see what was last updated. How do I do it autmomatically with my
code?
 
Thanks - that worked!

Drew

Cliff Harris said:
I had to figure this out a long time ago, and finally found a solution:

myTextBox.SelectionStart = myTextBox.Text.Length;
myTextBox.ScrollToCaret();

(I acutally put this in the TextChanged event of the textbox, so I never
have to worry about it)

HTH
-Cliff


that writes a message to it ever minute. What I want is to have the last
line of the text box always displayed. Right now, you have to scroll down
to get to see what was last updated. How do I do it autmomatically with my
code?
 
Beware though, this will only work if the text box has focus.

The other fool-proof way is to use Win32 interop to send message with
WM_VSCROLL set to SB_BOTTOM.

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top