Ich versuch schon den ganzen Tag den formatierten Text eines lzRichEdit auf die Canvas eines Image (Druckvorschau) zu bringen.
Ich habe dieses Beispiel (allerdings für ein RichEdit in Delphi) gefunden und angepaßt:
Code: Alles auswählen
uses RichEdit;
// Sonic Delphi
// soulyx@yahoo.com
function RTFtoBitmap(myRTF: TRichEdit; GiveSpaceForBorder: Integer): TBitmap;
// using myRTF parameter with your TRichEdit control name,
// default name "RichEdit1".
// For GiveSpaceForBorder parameter, sometimes you need to draw
// the RichEdit control with rectangle colorfull border, so you need
// to give space for it.
var
myRect: TRect;
temp: TBitmap;
begin
temp := TBitmap.Create;
myRect := myRTF.ClientRect;
// if you are using PRF_NONCLIENT parameter in myRTF.perform command
// using this statement
// myRect := Rect(0,0,MyRTF.Width,MyRTF.Height);
temp.Width := myRect.Right;
temp.Height := myRect.Bottom;
with temp.Canvas do
begin
Lock;
try
myRTF.Perform(WM_PRINT, Handle, PRF_CLIENT);
//you can trying to change PRF_CLIENT with
//PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT or PRF_ERASEBKGND
//or combine them. See what happen...
finally
Unlock
end;
end;
Result := TBitmap.Create;
Result := CreateEmptyBmp(clWhite,
temp.Width + GiveSpaceForBorder * 2,
temp.Height + GiveSpaceForBorder * 2);
Result.Canvas.Lock;
Result.Canvas.Draw(GiveSpaceForBorder, GiveSpaceForBorder, temp);
Result.Canvas.Unlock;
temp.Free;
end;
// Here's to put colorfull border
procedure MakeBorder(const bdr: TBitmap; BorderWidth: Integer; BorderColor: TColor);
begin
with bdr.Canvas do
begin
Brush.Style := bsClear;
pen.Width := BorderWidth;
pen.Color := BorderColor;
rectangle(BorderWidth - 1, BorderWidth - 1, bdr.Width, bdr.Height);
end;
end;
// Example how to using it
//
// var bmp : TBitmap;
// begin
// bmp := RTFtoBitmap(RichEdit1,2);
// MakeBorder(bmp,2,clBlue);
// Image1.Canvas.Draw(5,5,bmp);
// bmp.free;
// end;Zunächst ist mir die lzRichEdit.Perform-Routine immer mit einem Range Check error ausgestiegen.
Ich habe eben temporär die Bereichsprüfung ausgeschaltet, aber das verhindert halt nur den Runtime Error.
Weiß wer Rat?
ST
Christian