Click to See Complete Forum and Search --> : How to change view in RichTextBox ?
ryt
October 1st, 2008, 08:42 AM
I have a RichTextBox in which I receive some text. But after some time the text gets bigger and vertical scroll bars appear. So I keep receaving the text and the text goes down but my vertical scroll bars are left at top. So every time I receive new text I have to scroll down manualy.
Is there a way that I scroll down automaticly by program when I receive new text?
jasonli
October 1st, 2008, 09:01 AM
everytime after you add text into RichTextBox, just add one line:RichTextBox1.Select(RichTextBox1.Text.Length, 1);The vertical scroll bar will scroll automatically.
MMH
October 1st, 2008, 09:05 AM
Yes you can do that: Try this.
rtfText.SelectionStart = rtfText.TextLength;
rtfText.ScrollToCaret();
rfText.Select();
MMH
dannystommen
October 1st, 2008, 09:33 AM
I believe that only the ScrollToCaret() function is all that you need to do.
MMH
October 1st, 2008, 09:49 AM
I believe that only the ScrollToCaret() function is all that you need to do.
Only ScrollToCaret() won't work. This function will scroll the content of textbox to the caret position defined. And for that it is important to set the caret position to the length of the textbox.
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
So only these two lines are required.
MMH
ryt
October 1st, 2008, 10:22 AM
thx,
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
works but richTextBox behaves strange. If I am on the same line every time I recieve a new character scroll bar goes a little up, and than when I receive again new charachet scroll bar goes down. And like this all the time up and down.
Same thing happens with
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
richTextBox1.Select();
ryt
October 1st, 2008, 10:32 AM
I know whats the problem. I should make:
if(richTextBox1.newline == true)
move to carret;
But I dont know how to check if there is a newline on richTextBox1 since there is no .newline. Im also using wordwrap so I should check for that also.
jasonli
October 1st, 2008, 10:40 AM
Dunno why you don't solve it by only one line as I posted.
ryt
October 1st, 2008, 10:51 AM
Dunno why you don't solve it by only one line as I posted.
It doest work, the scroll bar wont move.
Also if I put only ScrollToCaret() it wont work.
I have fixed the problem:
if (currentLine < this.reciveRichTextBox.GetLineFromCharIndex(this.reciveRichTextBox.Text.Length))
{
this.reciveRichTextBox.SelectionStart = this.reciveRichTextBox.Text.Length;
this.reciveRichTextBox.ScrollToCaret();
}
currentLine = this.reciveRichTextBox.GetLineFromCharIndex(this.reciveRichTextBox.Text.Length);
ryt
October 2nd, 2008, 06:58 AM
The text scrolls, but I have some little problem. When I receive text, and when the richTextBox1 is full, scroll bars appear. When they appear, view automaticly scrolls down, but instantly view scrolls up. So the next line I cant see while Im receaving text, when the line is complete it goes to a new line, view scrolls down and everything is ok.
How can I fix this?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.