L
lccc
Unregistered / Unconfirmed
GUEST, unregistred user!
测试做了一个,也不难吗!!
type
TfrmPrintView = class(TForm)
btnPrint: TButton;
procedure btnPrintClick(Sender: TObject);
private
{ Private declarations }
M_RateX,M_RateY:Integer;
FCanvas:TCanvas;
FPrintForm:TForm;
procedure SetFont;
procedure PrintPaint(Sender: TObject);
procedure PrintText(const Preview:Boolean);
public
{ Public declarations }
end;
var
frmPrintView: TfrmPrintView;
implementation
uses Printers;
{$R *.DFM}
procedure TfrmPrintView.SetFont;
begin
//在以毫米为单位的位置(30,40)开始打印一行字
FCanvas.Font.Style:=[];
FCanvas.Font.Size :=10;
FCanvas.Font.Name :='宋体';
end;
procedure TfrmPrintView.PrintPaint(Sender: TObject);
begin
FCanvas.TextOut(30*M_Ratex,40*M_RateY,'测试打印内容!');
//画以毫米为单位的线,从(10,10)到(110,10)
FCanvas.Pen.Width :=1;
FCanvas.MoveTo(10*M_Ratex,10*M_Ratey);
FCanvas.LineTo(110*M_Ratex,10*M_Ratey) ;
end;
//以下是我直接在打印机里打 印内容的简单思路,实现了直接向打印机发送线或文本
procedure TfrmPrintView.PrintText(const Preview:Boolean);
begin
// 水平每毫米象素数, float
if Preview then
try
FPrintForm:=TForm.Create(Application);
FCanvas:=FPrintForm.Canvas;
with FPrintFormdo
begin
M_RateX:=0;//PixelsPerInch;///GetDeviceCaps(printer.Handle,HORZSIZE);
//铅直每毫米象素数, float
M_RateY:=0;//PixelsPerInch;///GetDeviceCaps(printer.Handle,VERTSIZE);
BorderStyle:=bsSingle;
BorderIcons:=[biSystemMenu];
Position:=poMainFormCenter;
OnPaint:=PrintPaint;
ShowModal;
end;
finally
FreeAndNil(FPrintForm);
FCanvas:=nil;
end else
with Printerdo
begin
M_RateX:=GetDeviceCaps(Handle,HORZRES);///GetDeviceCaps(printer.Handle,HORZSIZE);
//铅直每毫米象素数, float
M_RateY:=GetDeviceCaps(Handle,VERTRES);///GetDeviceCaps(printer.Handle,VERTSIZE);
//在以毫米为单位的位置(30,40)开始打印一行字
Canvas.Font.Style:=[];
Canvas.Font.Size :=10;
Canvas.Font.Name :='宋体';
Canvas.TextOut(30*M_Ratex,40*M_RateY,'测试打印内容!');
//画以毫米为单位的线,从(10,10)到(110,10)
Canvas.Pen.Width :=1;
Canvas.MoveTo(10*M_Ratex,10*M_Ratey);
Canvas.LineTo(110*M_Ratex,10*M_Ratey) ;
end;
end;
procedure TfrmPrintView.btnPrintClick(Sender: TObject);
begin
PrintText(True);
end;
end.
type
TfrmPrintView = class(TForm)
btnPrint: TButton;
procedure btnPrintClick(Sender: TObject);
private
{ Private declarations }
M_RateX,M_RateY:Integer;
FCanvas:TCanvas;
FPrintForm:TForm;
procedure SetFont;
procedure PrintPaint(Sender: TObject);
procedure PrintText(const Preview:Boolean);
public
{ Public declarations }
end;
var
frmPrintView: TfrmPrintView;
implementation
uses Printers;
{$R *.DFM}
procedure TfrmPrintView.SetFont;
begin
//在以毫米为单位的位置(30,40)开始打印一行字
FCanvas.Font.Style:=[];
FCanvas.Font.Size :=10;
FCanvas.Font.Name :='宋体';
end;
procedure TfrmPrintView.PrintPaint(Sender: TObject);
begin
FCanvas.TextOut(30*M_Ratex,40*M_RateY,'测试打印内容!');
//画以毫米为单位的线,从(10,10)到(110,10)
FCanvas.Pen.Width :=1;
FCanvas.MoveTo(10*M_Ratex,10*M_Ratey);
FCanvas.LineTo(110*M_Ratex,10*M_Ratey) ;
end;
//以下是我直接在打印机里打 印内容的简单思路,实现了直接向打印机发送线或文本
procedure TfrmPrintView.PrintText(const Preview:Boolean);
begin
// 水平每毫米象素数, float
if Preview then
try
FPrintForm:=TForm.Create(Application);
FCanvas:=FPrintForm.Canvas;
with FPrintFormdo
begin
M_RateX:=0;//PixelsPerInch;///GetDeviceCaps(printer.Handle,HORZSIZE);
//铅直每毫米象素数, float
M_RateY:=0;//PixelsPerInch;///GetDeviceCaps(printer.Handle,VERTSIZE);
BorderStyle:=bsSingle;
BorderIcons:=[biSystemMenu];
Position:=poMainFormCenter;
OnPaint:=PrintPaint;
ShowModal;
end;
finally
FreeAndNil(FPrintForm);
FCanvas:=nil;
end else
with Printerdo
begin
M_RateX:=GetDeviceCaps(Handle,HORZRES);///GetDeviceCaps(printer.Handle,HORZSIZE);
//铅直每毫米象素数, float
M_RateY:=GetDeviceCaps(Handle,VERTRES);///GetDeviceCaps(printer.Handle,VERTSIZE);
//在以毫米为单位的位置(30,40)开始打印一行字
Canvas.Font.Style:=[];
Canvas.Font.Size :=10;
Canvas.Font.Name :='宋体';
Canvas.TextOut(30*M_Ratex,40*M_RateY,'测试打印内容!');
//画以毫米为单位的线,从(10,10)到(110,10)
Canvas.Pen.Width :=1;
Canvas.MoveTo(10*M_Ratex,10*M_Ratey);
Canvas.LineTo(110*M_Ratex,10*M_Ratey) ;
end;
end;
procedure TfrmPrintView.btnPrintClick(Sender: TObject);
begin
PrintText(True);
end;
end.