1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
| procedure PaintRichedit(canvas:TCanvas;re:Trichedit;Bounds:Trect;pixelsperinch:Integer=96);
var fmt : TFormatRange; begin InflateRect(Bounds,-2,-2); Bounds.Left := Round(Bounds.Left * 1440 / pixelsperinch) ; Bounds.right := Round(Bounds.right * 1440 / pixelsperinch) ; Bounds.top := Round(Bounds.top * 1440 / pixelsperinch); Bounds.Bottom := Round(Bounds.Bottom * 1440 / pixelsperinch); with fmt do begin hdc:= Canvas.handle; hdcTarget:= hdc; chrg.cpMin := 0; rcPage := Bounds; rc := Bounds; chrg.cpMax := re.GetTextLen; end; SetBkMode( Canvas.Handle, TRANSPARENT ); re.perform( EM_FORMATRANGE, 1, integer( @fmt )); re.perform( EM_FORMATRANGE, 0, 0 ); end;
procedure TForm1.Button1Click(Sender: TObject); begin image1.Canvas.FillRect(image1.BoundsRect); PaintTo(image1.Canvas,0,0); PaintRichedit(image1.Canvas,TRichedit(DBrichedit1),DBrichedit1.BoundsRect); image1.Invalidate; end; |