473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

RichTextBox Question

JRB
I have a thread adding lines of text to a richtextbox on my windows form
about every 1 second. I want the last line of text to always be visible,
which it is until the box gets filled up. The last line is always visible if
the cursor is on the richtextbox, But if I'm working on another richtextbox
on the form, the one that is continually getting text doesn't scroll down
automatically. Is there any way to get it to automatically show the last
thing added to the richtextbox? I've tried scrollToCaret already, but if the
focus isn't on that richtextbox it sill doesn't work. Thanks.

JRB

Nov 16 '05 #1
2 2669
The only way I found to do this was to use the SendMessage API to send an
EM_LINESCROLL message. In my case I was always adding just one line at a
time so the following code worked:

[DllImport("user32.dll",EntryPoint="SendMessage")]
static extern int SendMessage(IntPtr Handle, int Msg, int WParam, int
LParam);
const int EM_LINESCROLL = 0xB6;
....
// After appending a line of text to the RichText control
SendMessage(richText1.Handle, EM_LINESCROLL, 0, 1);

If you're adding more than one line at a time, or if you want to scroll to
the end even if the user has scrolled away from the end, then you will need
to be a bit more clever and work out exactly how many lines you need to
scroll by.

Chris Jobson

"JRB" <JR*@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
I have a thread adding lines of text to a richtextbox on my windows form
about every 1 second. I want the last line of text to always be visible,
which it is until the box gets filled up. The last line is always visible
if
the cursor is on the richtextbox, But if I'm working on another
richtextbox
on the form, the one that is continually getting text doesn't scroll down
automatically. Is there any way to get it to automatically show the last
thing added to the richtextbox? I've tried scrollToCaret already, but if
the
focus isn't on that richtextbox it sill doesn't work. Thanks.

JRB

Nov 16 '05 #2
On Sun, 10 Oct 2004 12:27:03 -0700, JRB wrote:
But if I'm working on another richtextbox
on the form, the one that is continually getting text doesn't scroll down
automatically.


Simply set the RichTextBox's HideSelection property to false. New content
added should then auto-scroll into view, even if the control doesn't have
the focus.
Nov 16 '05 #3

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

Similar topics

6
by: Just Me | last post by:
I've seen code that copies a bmp file into a RichTextBox by first putting it into the clipboard and then using Paste to get it into the RichtextBox. This destroys the clipboard contents. Is...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
4
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
by: eBob.com | last post by:
After a lot of debugging effort I have to conclude that it does. Or at least can. I take a substring (RichTextBox.Text.Substring) before setting SelectionStart and after and get a different...
1
by: teo | last post by:
hallo I'm with vs2005 fw 2..0 is there a way to "freeze" the richtextbox, so to avoid user from editing it? I can Enable=False, but it no more scrolls and the font-color becomes grayed. ...
1
by: dshubhangi | last post by:
hi I've set richtextbox OLEDropMode Manual,catched OLEDragDrop event & in that event written below code Richtextbox1.OLEObjects.add ,,data.files(1) Now I'm able to catch OLEDragDrop as well as...
0
by: Linda Liu[MSFT] | last post by:
Hi CES, Thank you for posting here! I notice that you post a same issue in the microsoft.public.dotnet.framework.windowsforms.controls newsgroup and I have replied to that thread. For your...
1
by: Andrus | last post by:
I need to save font selected by user by Ctrl+MouseWheel in Winforms RichTextBox. I tried override below but this does not remember font: in this method Font.Size property seems to be always...
1
by: shakti s | last post by:
hi, My aplologies if this is really a silly question. I am trying to read contents like images and tables from one rich text box and paste it into another RTF control(i.e. another Richtextbox)....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.