A: Prints all visible TLabel, TEdit, TMemo, TDBText, TDBEdit and TDBMemo components on the form with proper place, size and font. Set the Form Scrollbar.Range to 768 Horz and 1008 Vert for a 8 X 10.5 page at 96formPPI.
USES Printers;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
C : array[0..255] of char;
CLen, ScaleX, ScaleY, I : integer;
Format : Word; DC : HDC;
MComp : TMemo; R: TRect;
begin
Printer.BeginDoc;
DC := Printer.Canvas.Handle;
ScaleX := GetDeviceCaps(DC, LOGPIXELSX) div PixelsPerInch;
ScaleY := GetDeviceCaps(DC, LOGPIXELSY) div PixelsPerInch;
for I := 0 to ComponentCount-1 do
if (Components[I] is TCustomLabel) or (Components[I]
is TCustomEdit) then
begin
MComp := TMemo(Components[I]);
if (MComp.visible) then
begin
Printer.Canvas.Font := MComp.Font;
DC := Printer.Canvas.Handle;
{so DrawText knows about font}
R := MComp.BoundsRect;
R.Top := (R.Top + VertScrollBar.Position)
* ScaleY;
R.Left := (R.Left + HorzScrollBar.Position)
* ScaleX;
R.Bottom := (R.Bottom +
VertScrollBar.Position) * ScaleY;
R.Right := (R.Right + HorzScrollBar.Position)
* ScaleY;
if (not(Components[I] is
TCustomLabel)) and (MComp.BorderStyle = bsSingle)
then Printer.Canvas.Rectangle(R.Left,R.Top,R.Right,R.Bottom);
Format := DT_LEFT;
if (Components[I] is TEdit)
or (Components[I] is TCustomMaskEdit) then
Format := Format
or DT_SINGLELINE or DT_VCENTER
else
begin
if MComp.WordWrap
then Format := DT_WORDBREAK;
if MComp.Alignment
= taCenter then Format := Format or DT_CENTER;
if MComp.Alignment
= taRightJustify then Format := Format or DT_RIGHT;
R.Bottom :=
R.Bottom + Printer.Canvas.Font.Height + 1;
end;
CLen := MComp.GetTextBuf(C,255);
R.Left := R.Left + ScaleX
+ ScaleX;
DrawText(DC, C, CLen, R,
Format);
end;
end;
Printer.EndDoc;
end;