To my surprise I have found out that rendering text repeatedly on a TCanvas is somehow "additive". I realise that the setting Canvas.Brush.Style:=bsClear
is the cause of the problem, but I really do need to render the text transparently and repeatedly (i.e in the OnPaint
event). After doing this the text doesn't look good.
How can I avoid that?
Here is some sample code; you can see the effect if you make several clicks on a TButton called btn1
.
procedure TForm1.btn1Click(Sender: TObject);
begin
Form1.Canvas.Brush.Style:=bsClear; //if you omit this, everything is OK.
Form1.Canvas.Font.Color:=clRed;
Form1.Canvas.Font.Name:='Times new Roman';
Form1.Canvas.Font.Style:=[fsBold];
Form1.Canvas.Font.Size:=12;
Form1.Canvas.TextOut(50,50,'www.stackoverflow.com');
end;