RE: RichTextbox scroll to a line

Tech-Archive recommends: Fix windows errors by optimizing your registry



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: RichTextbox scroll to a line
    ... Maybe I should just track the current character position intead. ... "caret" down that many lines (so that my desired line will end up as the ... > //have to set focus first on the rich text box for scrolling to work ... >> to have it scroll so that line displays at the top. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Difficulties in deriving a truly universal GUI Scripting Language
    ... interpretation, but yes, it *is* possible, although unlikely, the caret ... Even the rich edit control, in one of the most glaring API oversights I've ... In that case the script author would have to have the script do the same ... of spontaneously scroll underneath you. ...
    (microsoft.public.vc.mfc)
  • Re: Difficulties in deriving a truly universal GUI Scripting Language
    ... interpretation, but yes, it *is* possible, although unlikely, the caret ... Even the rich edit control, in one of the most glaring API oversights I've ... In that case the script author would have to have the script do the same thing ... of spontaneously scroll underneath you. ...
    (microsoft.public.vc.mfc)
  • Re: Difficulties in deriving a truly universal GUI Scripting Language
    ... expecting that's where the caret is going to end up. ... where the est is off the end of the control. ... of spontaneously scroll underneath you. ... The scripting language might not know to scroll, but the author of the script ...
    (microsoft.public.vc.mfc)
  • Re: Difficulties in deriving a truly universal GUI Scripting Language
    ... interpretation, but yes, it *is* possible, although unlikely, the caret could ... Even the rich edit control, in one of the most glaring API oversights I've ... In that case the script author would have to have the script do the same thing ... of spontaneously scroll underneath you. ...
    (microsoft.public.vc.mfc)