嗨,我有一個選單,其中有一個備忘錄的列印部分,現在我不知道如何單擊該部分來運行我找到的列印代碼。
如何鏈接或可能插入
PrintTStrings 程序的這一部分(Lst:TStrings);在程式
TForm1.MenuItemPrintClick (Sender: TObject) 的選單部分中;開始結束;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
end;
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
uj5u.com熱心網友回復:
您必須先宣告該PrintStrings程序,然后才能使用它。正確的方法是通過在表單宣告的部分中PrintTStrings宣告它來制作表單的方法:private
type
TForm1 = class(TForm)
// Items you've dropped on the form, and methods assigned to event handlers
private
procedure PrintTStrings(Lst: TStrings);
end;
然后,您可以直接從選單項的OnClick事件中呼叫它:
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;
如果由于某種原因你不能使它成為一個表單方法,你可以重新排列你的代碼:
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc ;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst[I]);
{Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns
a negative number. So Abs() is applied to the Height to make it a non-negative
value}
Line := Line Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
procedure TForm1.MenuItemPrinter(Sender: TObject);
begin
PrintTStrings(PrinterMemo.Lines);
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/471632.html
