我也在做打印的东西
才开始做
unit UOperPrint;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,printers,winspool;
type
TOperPrint=Class
private
FPrintLMargin : Integer;
FPrintTMargin : Integer;
FPrintRMargin : Integer;
FPrintBMargin : Integer;
FFontSize : Integer;
{打印字体大小}
FFontName : String;
{打印字体名字}
FFontStyle : TFontStyles;
{打印字体}
FPrinterOrientation : TPrinterOrientation;{打印横/竖}
function GetPrintrStr:String;
function GetPrintrCount:Integer;
function ConnPrinter(PrintrStr:String):Boolean;
procedure Print;virtual;
procedure SetPrintBMargin(const Value: Integer);
procedure SetPrintLMargin(const Value: Integer);
procedure SetPrintRMargin(const Value: Integer);
procedure SetPrintTMargin(const Value: Integer);
procedure SetFontname(const Value: String);
procedure SetFontSize(const Value: Integer);
procedure SetFontStyle(const Value: TFontStyles);
procedure SetPrinterOrientation(const Value: TPrinterOrientation);
protected
property PrintLMargin:Integer Read FPrintLMargin write SetPrintLMargin;
property PrintTMargin:Integer Read FPrintTMargin write SetPrintTMargin;
property PrintRMargin:Integer Read FPrintRMargin write SetPrintRMargin;
property PrintBMargin:Integer Read FPrintBMargin write SetPrintBMargin;
property FontSize:Integer read FFontSize write SetFontSize;
property FontName:String read FFontName write SetFontname;
property FontStyle:TFontStyles read FFontStyle write SetFontStyle;
property PrinterOrientation:TPrinterOrientation read FPrinterOrientation write SetPrinterOrientation;
public
end;
type
TPrintChar=class(TOperPrint)
private
FPrintResolution : Integer;{Char缩放的范围}
FPrintProportional :Boolean;
{是否按图象比例打印}
procedure SetPrintResolution(const Value: Integer);
procedure SetPrintProportional(const Value: Boolean);
protected
property PrintResolution:Integer read FPrintResolution write SetPrintResolution;
property PrintProportional:Boolean read FPrintProportional write SetPrintProportional;
procedure Print;overload;
public
property PrintLMargin;
property PrintTMargin;
property PrintRMargin;
property PrintBMargin;
property FontSize;
property FontName;
property FontStyle;
property PrinterOrientation;
end;
implementation
{ TOperPrint }
//****************************************************************************//
// *连接打印机* //
//****************************************************************************//
function TOperPrint.ConnPrinter(PrintrStr: String): Boolean;
begin
Result:=False;
try
if AddPrinterConnection(Pchar(PrintrStr)) then
Result:=True;
except
end;
end;
//****************************************************************************//
// *得到打印机数量* //
//****************************************************************************//
function TOperPrint.GetPrintrCount: Integer;
begin
Result:=Printer.Printers.Count;
end;
//****************************************************************************//
// *得到默认打印机* //
//****************************************************************************//
function TOperPrint.GetPrintrStr: String;
begin
if GetPrintrCount>0 then
Result:=Printer.Printers.Strings[0];
end;
procedure TOperPrint.Print;
begin
end;
procedure TOperPrint.SetFontname(const Value: String);
begin
FFontName := Value;
end;
procedure TOperPrint.SetFontSize(const Value: Integer);
begin
FFontSize := Value;
end;
procedure TOperPrint.SetFontStyle(const Value: TFontStyles);
begin
FFontStyle := Value;
end;
procedure TOperPrint.SetPrintBMargin(const Value: Integer);
begin
FPrintBMargin := Value;
end;
procedure TOperPrint.SetPrinterOrientation(
const Value: TPrinterOrientation);
begin
FPrinterOrientation := Value;
end;
procedure TOperPrint.SetPrintLMargin(const Value: Integer);
begin
FPrintLMargin := Value;
end;
procedure TOperPrint.SetPrintRMargin(const Value: Integer);
begin
FPrintRMargin := Value;
end;
procedure TOperPrint.SetPrintTMargin(const Value: Integer);
begin
FPrintTMargin := Value;
end;
{ TPrintChar }
procedure TPrintChar.Print;
begin
end;
procedure TPrintChar.SetPrintProportional(const Value: Boolean);
begin
FPrintProportional := Value;
end;
procedure TPrintChar.SetPrintResolution(const Value: Integer);
begin
FPrintResolution := Value;
end;
end.