How to make the rich text clear?

I have a little procedure that returns rich text into a canvas object, is there any way to get the canvas to be clear?

code:

procedure PaintRichEditTo(cnv : TCanvas; rc: TRect ; Editor: TRichEdit) ;
var Range: TFormatRange ;
    MaxLen, LogX, LogY: Integer ;
begin
  FillChar(Range, SizeOf(TFormatRange), 0) ;
  LogX := GetDeviceCaps(cnv.Handle, LOGPIXELSX) ;
  LogY := GetDeviceCaps(cnv.Handle, LOGPIXELSY) ;
  Range.hdc := cnv.Handle ;
  Range.hdcTarget := Range.hdc ;
  Range.rc.left := rc.Left * 1440 div LogX ;
  Range.rc.top := rc.Top * 1440 div LogY ;
  Range.rc.right := rc.Right * 1440 div LogX;
  Range.rc.bottom := rc.Bottom * 1440 div LogY;
  Range.rcPage := Range.rc ;
  MaxLen := Editor.GetTextLen ;
  Range.chrg.cpMax := MaxLen ;
  Range.chrg.cpMin := 0 ;
  SendMessage(Editor.Handle, EM_FORMATRANGE, 1, Longint(@Range)) ;
end ;
JazCAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DrDelphiConnect With a Mentor Commented:
thanks!!
0
 
DrDelphiCommented:
I'm not sure what you mean by clear. If you mean transparent, you should be able to set the Canvas' Brush.Style:=BsClear
0
 
edeyCommented:
or if you want to redraw the canvas:

canvas.brush.color := fill_color;
canvas.fillRect(rect(left,top,width,height);

or to redraw the richedit:

invalidateRect(richEdit.handle,nil,true);

or too clear the richedit defore drawing:

richEdit.lines.clear;

As DrDelphi said, a little more info would be helpfull.


GL
Mike
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
JazCAuthor Commented:
I'm Sorry,

I am printing the rich edit control, thefore sending the Printer Canvas as the canvas object. But sometimes there may already be an object on the canvas, such as a  bitmap. I want to be able to print the richedit over the bitmap, but for the background to be clear. So that the bitmap shows through.

Is that any better, I could send some more code if it helps.

Regards
Jason Coley
0
 
simonetCommented:
Following...®
0
 
edeyCommented:
then setting

canvas.brush.style := bsClear;

should work, if not then you may have to blt it with a mask.


GL
Mike
0
 
JazCAuthor Commented:
Put it in as an answer and I will give you the points, I can't believe it was so easy.

Thanks
Jason
0
 
edeyCommented:
Dr. Delphi, I presume :)
0
 
JazCAuthor Commented:
Oh, sorry no you edey, worked pretty good, but now when I print a rich edit field where the text is set to white it comes out black, do you have any idea why this happens?
0
 
JazCAuthor Commented:
Sorry, you are correct Dr Delphi has it!
0
 
edeyCommented:
As to this, I'm afraid, I don't know.  Perhaps the TRichEdit doesn't cleanly paint it's self, does it only happen with white text?


GL
Mike
0
 
JazCAuthor Commented:
seems to, oh well I guess I will have to keep hacking at it, if you get an idea to try please email me on

Jason@software-solutions.co.nz


Regards Jasonj
0
All Courses

From novice to tech pro — start learning today.