Hartelijke dank voor jullie code.
Ik zal er van kunnen genieten!
Deze code kan nog heel nuttig zijn voor andere amateur-programmeurs zoals ik.
Hier de code in mijn programma:
Code:
procedure TForm1.BtnPRINTFORMClick(Sender: TObject);
// Put "Math" in uses
var
myBitMap : TBitMap;
rct: TRect;
HScaleFactor, VScaleFactor: Single;
BWidth, BHeight: Integer;
PWidth, PHeight: Integer;
RTop, RLeft, RBottom, RRight: Integer;
begin
if not PrintDialog1.Execute then Exit;
HScaleFactor := Printer.XDPI / Screen.PixelsPerInch;
VScaleFactor := Printer.YDPI / Screen.PixelsPerInch;
try
myBitMap := TBitMap.Create;
Printer.Refresh;
// Maximum Width / Height of image (Formsize) = 910x510
// else picture will not fit in page A4-Portrait.
Printer.Orientation:= poLandscape;
myBitMap.LoadFromDevice(Canvas.Handle);
// Bitmap width / height
BWidth := trunc(myBitMap.Width*HScaleFactor);
BHeight := trunc(myBitMap.Height*VScaleFactor);
// Printer page width / height
PWidth := Printer.PageWidth;
PHeight := Printer.PageHeight;
// Calculate center of bitmap on printer canvas
RTop := max(0, ((PHeight div 2) - (BHeight div 2)));
RLeft := max(0, ((PWidth div 2) - (BWidth div 2)));
RBottom := min(PHeight, (RTop + BHeight));
RRight := min(PWidth, (RLeft + BWidth));
// Set rect
rct := Rect(Rleft, RTop, RRight, RBottom);
Printer.BeginDoc;
Printer.Canvas.StretchDraw(rct, myBitMap);
finally
Printer.EndDoc;
myBitMap.Free;
end;
end;
Bookmarks