📄 dfwprintpreviewsampleformu.pas
字号:
unit DFWPrintPreviewSampleFormU;
interface
uses
WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DFWPreview;
type
TForm1 = class(TForm)
DFWPrintPreview1: TDFWPrintPreview;
Panel1: TPanel;
Button1: TButton;
ComboBox1: TComboBox;
Button2: TButton;
Label1: TLabel;
Label3: TLabel;
Image1: TImage;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure Button2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DFWPrintPreview1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
if DFWPrintPreview1.State = psReady then
DFWPrintPreview1.Print;
ActiveControl := DFWPrintPreview1;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case ComboBox1.ItemIndex of
0: DFWPrintPreview1.Zoom := 50;
1: DFWPrintPreview1.Zoom := 100;
2: DFWPrintPreview1.Zoom := 150;
3: DFWPrintPreview1.Zoom := 200;
4: DFWPrintPreview1.ZoomState := zsZoomToWidth;
5: DFWPrintPreview1.ZoomState := zsZoomToFit;
end;
ActiveControl := DFWPrintPreview1;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I, FontSize: Integer;
R: TRect;
begin
Randomize;
with DFWPrintPreview1 do
begin
R := PageRect;
BeginDoc;
FontSize := Canvas.Font.Size;
for I := 0 to 25 do
begin
Inc(FontSize, I);
Canvas.Font.Size := FontSize;
Canvas.Font.Color := RGB(Random(256), Random(256), Random(256));
if (R.Top - Canvas.Font.Height) > PageRect.Bottom then
begin
NewPage;
Canvas.Font.Size := FontSize;
R := PageRect;
end;
R.Bottom := R.Top - Canvas.Font.Height;
Canvas.TextRect(R, R.Left, R.Top, 'This is a sample text');
R.Top := R.Bottom;
end;
NewPage;
R.Left := (PaperWidth - Image1.Width) div 2;
R.Right := (PaperWidth + Image1.Width) div 2;
R.Top := (PaperHeight - Image1.Height) div 2;
R.Bottom := (PaperHeight + Image1.Height) div 2;
InflateRect(R, 15 * Image1.Width, 15 * Image1.Height);
Canvas.StretchDraw(R, Image1.Picture.Graphic);
EndDoc;
end;
ActiveControl := DFWPrintPreview1;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex := 5;
end;
procedure TForm1.DFWPrintPreview1Change(Sender: TObject);
begin
if DFWPrintPreview1.CurrentPage <> 0 then
begin
with DFWPrintPreview1 do
Label3.Caption := Format('Page %d of %d', [CurrentPage, TotalPages]);
Label3.Update;
end
else
Label3.Caption := 'Empty';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
DFWPrintPreview1.CurrentPage:=TComponent(Sender).tag;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -