Maybe I should just track the current character position intead. Now that I
think of it, that's just as easy to do -- it's just that the line index was
what I needed for other purposes, so it's what I was tracking. But it's easy
to do GetLineFromCharIndex(), and not so easy the other way 'round. I don't
feel a whole lot of confidence that I can always count on exactly one
character between each line... (which is what I'm seeing in my testing...
just the '\n' -- which is translated to a "/r/n" in the .Rtf property.
In order for ScrollToCaret to do what I really want, I'll also need to know
whether my initial position is above or below the place I want to scroll to,
and if it's above (so I'm scrolling down)... oh, thats the problem, though.
I can figure out how many lines are showing in the control, but to get the
"caret" down that many lines (so that my desired line will end up as the
first line, not the last), I will still need to be able to find a character
position n lines down ...
Why is this so hard? Some part of the control has to know which line its
characters are on to draw them correctly... why don't I have access to that
info?
I could try GetCharIndexFromPosition() where the Position argument has a Y
close to RichTextBox.ClientSize.Height * 2, and then ScrollToCaret a second
time... maybe that would work, but it seems unnecessarily complicated, and I
don't know how it would look.
-Rachel
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:27**********************************@microsof t.com...
Hi Rachel,
one way to do it would be the following:
//have to set focus first on the rich text box for scrolling to work
this.richTextBox1.Focus();
//move the caret to the correct place <IMPO>This is a character position
not line position</IMPO>
this.richTextBox1.SelectionStart = 50;
this.richTextBox1.ScrollToCaret();
I don't think there is a method for setting to caret to an individual
line, so you will have to calculate the position of the caret by knowing how
many characters there are in each line (plus the \r\n)
Hope that helps
Mark.
"Rachel Suddeth" wrote:
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 scroll is with ScrollToCaret(). But I
don't know how to set the "caret" to a particular line.
Any suggestions?
-Rachel