Re: RichTextbox scroll to a line

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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" <MarkRDawson@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2740E80C-1826-4A32-9222-568586FD49F5@xxxxxxxxxxxxxxxx
> 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
> >
> >
> >


.



Relevant Pages

  • Re: SSC firmware - incorrect handshake?
    ... char of every line gets lost if the Apple needs to scroll. ... I do use handshaking and the handshake seems to work correctly, ... no data will be sent to the Apple. ... serviced as soon as a character arrives. ...
    (comp.sys.apple2)
  • Re: Single use command considered harmful
    ... care whether he quaffs it, reads its, or waves it. ... Why do you want to use a potion, ... a scroll doesn't make the potion less of a potion or the scroll less ... The next step is making "a magic user" character class, ...
    (rec.games.roguelike.development)
  • Re: Two Questions
    ... where the character seems to stick up above ... I can get neither the tabbed panes nor scrolled pane ... a scroll bar in, but it wouldn't auto-size to the frame. ... > poor eyesight and need to use a font that is larger than that used by ...
    (comp.lang.java.gui)
  • Re: RichTextBox Horizontal Scroll
    ... I've already sized the extent of this font ... and have calculated the effective height and width of each character. ... I am scrolling the RichTextBox in synch with some other controls using ... there are some annoying problems with these scroll bar ...
    (microsoft.public.vb.controls)
  • RE: RichTextbox scroll to a line
    ... //have to set focus first on the rich text box for scrolling to work ... I don't think there is a method for setting to caret to an individual line, ... "Rachel Suddeth" wrote: ... > The only way I can see to make it scroll is with ScrollToCaret. ...
    (microsoft.public.dotnet.languages.csharp)