用Delphi实现打印功能,用Delphi实现打印功能
【 tulaoshi.com - Delphi 】
procedure TForm1.Button1Click(Sender: TObject);
var StrLen , Left,Top , WordHeight , wordWidth : Integer;
ContentStr : String[100];
Str1, Str2, Str3 : String[36];
begin
with Printer do
begin
Canvas.Font.Size:=16;
wordHeight:=Canvas.TextHeight
('字');
wordWidth:=Canvas.TextWidth
('字');
Left:=(Printer.PageWidth-wordWidth*22) div 2;
Top:=(Printer.PageHeight-wordHeight*7) div 2;
BeginDOC;
With Canvas do
begin
Pen.Width:=3;
{画一个22字宽,7个字高的矩形框}
MoveTo(Left,Top);
LineTo(Left+wordWidth*22,Top);
LineTo(Left+wordWidth*22,
Top+wordHeight*7);
LineTo(Left,Top+wordHeight*7);
LineTo(Left,Top);
ContentStr:=Memo1.Lines.Text;
StrLen:=Length(ContentStr);
if StrLen< 37 then
{分一行打印}
begin
TextOut(Left+WordWidth*2, Top+Wordheight*3, ContentStr)
end
else if StrLen< 66 then
{在垂直方向中间分两行打印}
begin
Str1:=Copy(ContentStr, 0, 32);
Str2:=Copy(ContentStr, 33, StrLen-32);
TextOut(Left+WordWidth*4, Top+WordHeight*(7-2) div 2 , Str1);
TextOut(Left+WordWidth*2, Top+WordHeight*(7-2) div 2 + wordHeight, Str2);
end
else
{分三行打印}
begin
Str1:=Copy(ContentStr,0,32);
Str2:=Copy(ContentStr,33,36);
Str3:=Copy(ContentStr, 69, StrLen-68);
TextOut(Left+WordWidth*4, Top+WordHeight*2, Str1);
{左缩进两个汉字}
TextOut(Left+WordWidth*2, Top+WordHeight*3, Str2);
TextOut(Left+WordWidth*2, Top+WordHeight*4, Str3);
end
end;
EndDoc;
end;
end;
来源:http://www.tulaoshi.com/n/20160129/1492776.html
看过《用Delphi实现打印功能》的人还看了以下文章 更多>>