473,405 Members | 2,262 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,405 software developers and data experts.

RichTextBox scrolling problem

Udi
Hi,
I need to update the last line of Lines in my derived RichTextBox.
Since I can't do this:

Lines[Lines.Length -1] = history[historyIdx] as string;

I need to copy 'Lines' to a tmp array, change it and copy it back to
'Lines':

:
tmpTxtMatrix = new string[....];
Lines.CopyTo(tmpTxtMatrix, 0);

//Replace last line in console with history value
tmpTxtMatrix[tmpTxtMatrix.Length - 1] = history[historyIdx] as string;

//Setting the new lines array
Lines = tmpTxtMatrix;
SelectionStart = this.TextLength;
this.ScrollToCaret();
:

My problem is that this procedure causes the textBox to scroll up to
the begining of it, and then scroll back down to the last line.
Is there a way to update the last line without copying all lines?
If not, how do I prevent the scroll side effect?
Thanks!
Udi

Jul 6 '06 #1
1 2219
Udi,

Here is an idea how to solve both your problems

int lastLineIndex = this.richTextBox1.Lines.Length - 1;
int lastLineFirstCharIndex =
this.richTextBox1.GetFirstCharIndexFromLine(lastLi neIndex);
int lastLineLength = richTextBox1.SelectionStart =
richTextBox1.Lines[lastLineIndex].Length;

this.richTextBox1.SelectionStart = lastLineFirstCharIndex;
this.richTextBox1.SelectionLength = lastLineLength;
this.richTextBox1.SelectedText = "New Last Line";
this.richTextBox1.ScrollToCaret();
this.richTextBox1.SelectionStart = lastLineFirstCharIndex;

--
HTH
Stoitcho Goutsev (100)
"Udi" <Ud**********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,
I need to update the last line of Lines in my derived RichTextBox.
Since I can't do this:

Lines[Lines.Length -1] = history[historyIdx] as string;

I need to copy 'Lines' to a tmp array, change it and copy it back to
'Lines':

:
tmpTxtMatrix = new string[....];
Lines.CopyTo(tmpTxtMatrix, 0);

//Replace last line in console with history value
tmpTxtMatrix[tmpTxtMatrix.Length - 1] = history[historyIdx] as string;

//Setting the new lines array
Lines = tmpTxtMatrix;
SelectionStart = this.TextLength;
this.ScrollToCaret();
:

My problem is that this procedure causes the textBox to scroll up to
the begining of it, and then scroll back down to the last line.
Is there a way to update the last line without copying all lines?
If not, how do I prevent the scroll side effect?
Thanks!
Udi

Jul 6 '06 #2

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

Similar topics

2
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...
0
by: Aku | last post by:
Hello, I have a RichTextBox located in a TabPage area; when I enter the RTBox space I displayed a certain text on it (using MouseEnter event). When I leave the RTBox space I displayed another...
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
3
by: Rachel Suddeth | last post by:
I want to react to scrolls in a RichTextBox (I want to let the user know when he has changed to a new printable page.) I have handled the VScroll() event, but that only responds to scrollbar...
8
by: Grant Schenck | last post by:
I have code where I append text to a rich text box. I grab the current SelectionStart and SelectionLength before I append the text and then after I reset the SelectionStart and SelectionLength to...
0
by: Jean-Francois Lord | last post by:
Hello, I have a multithreaded windows app that has a RichTextBox acting as an output console for the worker threads. I need a way of scrolling down to the bottom of the RichTextBox as text is...
4
by: D. Yates | last post by:
Hi, When a RichTextBox control doesn't have focus, it DOES NOT scroll to the last line that is added; however, if it does have focus, it WILL scroll to the last line added. I want to stop and...
1
by: dotnetnoob | last post by:
i have a Dialog form with richtextbox that basically display a legal agreement and when the user drag the scroll thumb down to the end of scrolling which suppose to mean the user have read it then...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
8
by: Tom | last post by:
Inserting text into a RichTextBox is a snap! >> textBox1.Text += "Enter string 0000\n"; textBox1.Text += "Enter string 0001\n"; textBox1.Text += "Enter string 0002\n"; textBox1.Text += "Enter...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.