Solved

How to scroll richedit smoothly?

Posted on 2000-02-22
10
1,297 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now