Solved

How to scroll richedit smoothly?

Posted on 2000-02-22
10
1,311 Views
Last Modified: 2013-11-22
ScrollBy function can only scrool the visible part of the richedit component,and richedit.perform(WM_VSCROLL,SB_LINEDOWN,0) can only scroll it by one line.
I want to scroll it smoothly,how to do it?
0
Comment
Question by:limin_chen
10 Comments
 

Expert Comment

by:mike_tipping
ID: 2546380
Place the richedit in a panel and increase the size of the richedit box to the full length of the RE document (either at design time or dinamically according to what is load into it). Only the section of the REB in the pannelo will be visible but if you increase and devrease the value of the rich edits top property the richedir box will slide up and down within the panel and give the impression of scrolling.

This may sound a bit of a cheat but it's the only way I could find to do it and it has worked fine so far.
0
 
LVL 6

Expert Comment

by:edey
ID: 2546603
Another method would be to keep a full sized, hidden, rich edit, draw the thing to an off screen bmp and blt chunks of it to a scrollable control.  Note, this would work *muc* better with a read-only rich edit, in this case you wouldn't even have to keep the rich edit at all


Gl
Mike
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2547018
listenning
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:limin_chen
ID: 2548498
To edey:
  I like your method more.
  But if the richedit box is invisible or if it was created in program,the program here:
var
    back:tbitmap;
begin
  back:=tbitmap.create;
  back.canvas.width:=richedit.width;
  back.canvas.heigth:=richedit.height;
  bitblt(back.canvas.handle,0,0,back.canvas.width,back.canvas.height,getdc(richedit.handle),0,0,SRCCOPY);
  bitblt(mainform.canvas.handle,0,0,richedit.width,richedit.height,back.canvas.handle,0,0,SRCCOPY);
end;
  It could not get the correct image of the current richedit box,It is just filled with white color.I dont know the reason.
0
 

Author Comment

by:limin_chen
ID: 2548888
Mike tipping:
  could you please tell me how to get the full lenght of the RE document displayed in RE box?
0
 

Expert Comment

by:mike_tipping
ID: 2549568
Increase The Height, the following code is probably not a brilliant as it could be but it works. Hide the Richedit box or Panel, and set

richedit1.height := Reditlength;

Then Show whichever you hid. If you don't do this you se the Reditlength function scanning the text.



Function TForm1.Reditlength;
Var
  nHeight, i, nSelStart : Integer;
Begin
  nSelStart := 1;
  {character to start scanning from}
  nHeight := 6;{this is the gap
                before the first text}
  For i:= 0 to Pred(Richedit1.Lines.Count) do
  begin
    Richedit1.SelStart := nSelStart;
    Richedit1.SelLength := 5;
    {scan 5 Characters in each line}
    nHeight := nHeight + RichEdit1.SelAttributes.Height + 3;
    {+3 for the gap between lines}
    nSelStart := nSelStart + Length(Richedit1.Lines.Strings[1]);
  end{for};
  REditLength := nHeight;
End;
0
 

Author Comment

by:limin_chen
ID: 2549671
I found a better method to get the actul lines in pixel.Does it work right?

var
  h:integer;
begin
 richedit.peform    (wm_vscroll,sb_bottom,0);
 h:=getscrollpos(richedit.handle,sb_vert);
 inc(h,richedit.height);
{So ,I think the var h is the total lines in pixel}
0
 

Expert Comment

by:mike_tipping
ID: 2550102
It looks like this gives the position on the screen of the scroll bar toggle (thumb), not the length on the rich edit box

I presume your trying to scroll the richedit box with scroll bars switched off which would mean that getscrollpos returns 0 as there are no scroll 'thumbs' to get the position of.

I guess with ebey's solution your going to need to expand the rich edity box to it's full height as well, which gives us the same problem, how to get the length of the contents of the richedit box in pixels.
0
 
LVL 1

Expert Comment

by:duke_n
ID: 2550450
Var
Line:integer;
begin
Line:=20;//or something
SendMessage(RE.Handle, EM_LINESCROLL,0,MAKELONG(word(Line-(GetScrollPos(RE.Handle,SB_VERT)div 13)),0));//13-My Richedit's linesize
end;

this one works smoothly for me
0
 

Accepted Solution

by:
mike_tipping earned 100 total points
ID: 2564421
so who gets the points?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question