473,484 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Text Box - Move to last line.

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
Nov 16 '05 #1
5 18244
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" <Dr**@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
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

Nov 16 '05 #2
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" <Dr**@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
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

Nov 16 '05 #3
Thanks - that worked!

Drew

"Cliff Harris" wrote:
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" <Dr**@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
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


Nov 16 '05 #4
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

"Cliff Harris" <he***@myrealbox.com> wrote in message
news:ed****************@TK2MSFTNGP09.phx.gbl...
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" <Dr**@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
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


Nov 16 '05 #5
use AppendText() method
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10206
by: Charles Erwin | last post by:
Is there any way, upon scanning in a file line by line to avoid missing the last line if there is not a newline character (aka you have to hit return on the last line of input in your file). I was...
2
3954
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
2
33881
by: Tarren | last post by:
Hi: I want to check my text file to ensure the last line has only DONE on it, prior to loading the file. How can I do this with a StreamReader object to go to the last line so I can perform...
2
3798
by: Eric Lilja | last post by:
Hello, I'm writing a simple program that upon start-up needs to open a text file and read a value on the last line. Then all other accesses to the file will be writes (at the end of it). I'm having...
35
11327
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
7
25847
by: DemonWasp | last post by:
I've been having some trouble getting the Scanner class to operate the way I'd like. I'm doing some fairly basic file IO and I can't seem to get the class to load the last line/token any way I try....
6
5761
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
4
5947
by: Franky | last post by:
What I want to do is delete the last line in a RichTextBox. The RichTextBox has a ReadOnly property called lines that seems like it might help but I cant figure out how to use it. Well, the...
1
905
by: BarryM | last post by:
Say if there is a bunch of writing in a text box and you want to change the first line to lets say "line 1" and the last line to "last line" but keep the lines in the middle the same text, how can i...
0
7082
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6953
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6813
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4845
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1359
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.