?? unit1.~pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,Printers;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Memo2: TMemo;
PrintDialog1: TPrintDialog;
PrinterSetupDialog1: TPrinterSetupDialog;
Image1: TImage;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
P:TextFile;
ln:integer;
begin
if PrintDialog1.Execute then
begin
AssignPrn(P);
rewrite(P);
Writeln(P,'姓名:'+Edit1.Text);
Writeln(P,'性別:'+Edit2.Text);
Writeln(P,'年齡:'+Edit3.Text);
Writeln(P,'電話:'+Edit4.Text);
Writeln(P,'備注:');
Printer.Canvas.Font:=Memo2.Font;
for ln:=0 to Memo2.Lines.Count-1 do
Writeln(p,memo2.lines[ln]);
CloseFile(P);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ln:integer;
begin
if PrintDialog1.Execute then
begin
printer.BeginDoc;
Printer.Title:='打印文本';
Printer.Canvas.Font:=Memo1.Font;
for ln:=0 to Memo1.Lines.Count-1 do
printer.Canvas.TextOut(10,30*ln,Memo1.Lines[ln]);
printer.EndDoc;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
strect:Trect;
hi,wd:integer;
begin
if printDialog1.Execute then
begin
hi:=image1.Picture.Height;
wd:=image1.Picture.Width;
while(hi=printer.PageHeight div 2)and(wd=printer.PageWidth div 2)do
begin
hi:=hi+hi;
wd:=wd+wd;
end;
with strect do
begin
left:=(printer.PageHeight-hi)div 2;
top:=(printer.PageWidth-wd)div 2;
right:=left+wd;
bottom:=top+hi;
end;
with printer do
begin
begindoc;
canvas.StretchDraw(strect,image1.Picture.Graphic);
enddoc;
end;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -