Solved

How to scroll richedit smoothly?

Posted on 2000-02-22
10
1,299 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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