Board index » delphi » Scroll a richedit line to top

Scroll a richedit line to top

Hi

How can I scroll a given richedit line to top, i.e., make it the first
visible line?

tia

--
  luu
Please remove the underscore _ in my address if you wish to reply by email.

 

Re:Scroll a richedit line to top


RichEdit1.SelStart := 0;

Cameron
_______________________
cameronm...@hotmail.com

Quote
Luu Tran wrote in message

<8D5E966CEluutrangeocities...@news.mindspring.com>...
Quote
>Hi

>How can I scroll a given richedit line to top, i.e., make it the first
>visible line?

>tia

>--
>  luu
>Please remove the underscore _ in my address if you wish to reply by email.

Re:Scroll a richedit line to top


Setting SelStart to zero positions to the start of the file--it
doesn't position a particular line at the top of the screen. I also
would like to see an efficient way to do this. Inefficiently, you can
scroll to the end of the file, add blanks until the last line of the
file is at the top of the screen, then scroll back line by line. This
might work. There must be a better way!

Herbert Gintis

Herbert M Gintis
Professor of Economics
University of Massachusetts
413-586-7756 (Home/Office)
413-586-6014 (Fax)
gin...@econs.umass.edu
http://www-unix.oit.umass.edu/~gintis              

Re:Scroll a richedit line to top


procedure TForm1.ScrollToLine(LineNumber:Integer);
var
 TempLine:Integer;
 ScrollResult:Boolean;
begin
  TempLine:=RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);
  ScrollResult:=RichEdit1.Perform(EM_LINESCROLL,0,(LineNumber-TempLine))

 {Note:If ScrollResult:=False then an Error occurred}
end;

Re:Scroll a richedit line to top


Scratch that...I misread !
I thought it had to be a boolean return...it doesn't

CORRECTED..(I Think:))

procedure TForm1.ScrollToLine(LineNumber:Integer);
var
 TempLine:Integer;
begin
  TempLine:=RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);
  RichEdit1.Perform(EM_LINESCROLL,0,(LineNumber-TempLine));

end;

Re:Scroll a richedit line to top


NolenJ <nol...@aol.com> wrote in
<19990131103339.02654.00002...@ng35.aol.com>:

Thank you.  This works beautifully :)

Only minor problem is the caret remains where it was.  A small tweak will
fix this:

// make LineNumber the first visible line in Memo
procedure ScrollLineToTop( Memo: TCustomMemo; LineNumber:Integer);
var
 TempLine:Integer;
begin
  with Memo do
  begin
    // scroll relative to the first visible line
    TempLine:=Perform(EM_GETFIRSTVISIBLELINE,0,0);
    Perform(EM_LINESCROLL,0,(LineNumber-TempLine));
    // move the caret
    SelStart:=Perform( EM_LINEINDEX, LineNumber, 0);
    Perform( EM_SCROLLCARET, 0, 0);
  end;
end;

--
  luu
Please remove the underscore _ in my address if you wish to reply by email.

Re:Scroll a richedit line to top


Ignore that message if it hasn't been cancelled properly.  What I meant to
say was:

I thought the SelStart worked, but maybe not.  Here is a better way of doing
it.

    PostMessage(RichEdit1.Handle,
EM_LINESCROLL, -32767, -RichEdit1.Lines.Count);

The EM_LINESCROLL message will tell the rich edit (or memo) to scroll
relative to the current position.  (I can't seem to find a message for an
absolute position, though; if someone finds one, please tell me.)  It's very
unlikely you'll have more than 32K columns in your rich edit, and -32767 is
the lowest value you can use here.

Because you know the number of lines in your rich edit, you can say "scroll
back RichEdit1.Lines.Count lines".  This will make sure it is at the first
line.

Good luck,

Cameron
_______________________
cameronm...@hotmail.com

Quote
Cameron McCormack wrote in message <792ua7$5d...@news.alphalink.com.au>...
>I thought the SelStart worked, but maybe not.  Here is the proper way of
>doing it.  Try this:

>    PostMessage(RichEdit1.Handle, EM_LINESCROLL, col, row);

>col is the zero-based column you want at the left of the memo or rich edit,
>and row is the zero-based row you want at the top.  So, to scroll it to the
>start, make col and row equal 0.

>HTH,

>Cameron
>_______________________
>cameronm...@hotmail.com

>Herbert Gintis wrote in message <36b40dfc.40354...@news.oit.umass.edu>...
>>Setting SelStart to zero positions to the start of the file--it
>>doesn't position a particular line at the top of the screen. I also
>>would like to see an efficient way to do this. Inefficiently, you can
>>scroll to the end of the file, add blanks until the last line of the
>>file is at the top of the screen, then scroll back line by line. This
>>might work. There must be a better way!

>>Herbert Gintis

>>Herbert M Gintis
>>Professor of Economics
>>University of Massachusetts
>>413-586-7756 (Home/Office)
>>413-586-6014 (Fax)
>>gin...@econs.umass.edu
>>http://www-unix.oit.umass.edu/~gintis

Other Threads