📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Printers, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
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 :=20;
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<17 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+WordWidth*3,Str2);
TextOUt(Left+WordWidth*2,Top+WordWidth*4,Str2);
end
end ;
endDoc;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -