unit UPrint;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,Printers;//Printers
type
TFPrint = class(TForm)
PrinterSetupDialog1: TPrinterSetupDialog;
PrintDialog1: TPrintDialog;
BPrint: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
BSet: TButton;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
procedure BPrintClick(Sender: TObject);
procedure BSetClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FPrint: TFPrint;
implementation
{$R *.dfm}
procedure TFPrint.FormCreate(Sender: TObject);
begin
TabSheet1.Caption :='页面一';
TabSheet2.Caption :='页面二';
TabSheet3.Caption :='页面三';
TabSheet4.Caption :='页面四';
BSet.Caption :='页面设置...';
BPrint.Caption :='打印...';
end;
procedure TFPrint.BSetClick(Sender: TObject);
begin
PrinterSetupDialog1.Execute;
end;
procedure TFPrint.BPrintClick(Sender: TObject);
var
FirstPage, LastPage: Integer;
i:integer;
begin
//设置打印对话框的选项
PrintDialog1.Options := [poPageNums, poSelection];
PrintDialog1.FromPage := 1;
PrintDialog1.MinPage := 1;
PrintDialog1.ToPage := PageControl1.PageCount;
PrintDialog1.MaxPage := PageControl1.PageCount;
//显示打印对话框
if PrintDialog1.Execute then
begin
//确定用户所选择的打印范围
with PrintDialog1 do
begin
if PrintRange = prAllPages then
begin
FirstPage := MinPage - 1;
LastPage := MaxPage - 1;
end
else if PrintRange = prSelection then
begin
FirstPage := PageControl1.ActivePage.PageIndex;
LastPage := FirstPage;
end
else // PrintRange = prPageNums 的情况
begin
FirstPage := FromPage - 1;
LastPage := ToPage - 1;
end;
end;
//开始打印
with Printer do
begin
BeginDoc;
for i := FirstPage to LastPage do
begin
PageControl1.Pages[I].PaintTo(Handle, 10, 10);
if i <> LastPage then
NewPage;
end;
EndDoc;
end;
end;
end;
end.
实现打印功能
最新推荐文章于 2025-08-22 16:46:43 发布
本文介绍了一个基于Delphi的打印组件实现方案,通过创建多个页面并利用按钮触发打印设置和打印操作。文章详细展示了如何设置打印对话框的选项、执行打印范围的选择以及如何将页面内容打印到指定打印机。
3515

被折叠的 条评论
为什么被折叠?



