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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
DrDelphiCommented:
thanks!!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.