博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Memo打印1
阅读量:4564 次
发布时间:2019-06-08

本文共 3160 字,大约阅读时间需要 10 分钟。

 
 
 
 
 
Delphi 打印Memo里面的内容 实现的功能和记事本的打印的功能一样
打印保存为文件时此时的文件名如何设置?
当Memo里的文本数量巨大时 窗体正在打印会出现点数字显示问题 闪烁
 
PageSetup没做任何功能

 
 
 
 
 
 
 
 
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1
=
class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    Button2: TButton;
    PrinterSetupDialog2: TPrinterSetupDialog;
    PrintDialog2: TPrintDialog;
    Label1: TLabel;
    
procedure Button1Click(Sender: TObject);
    
procedure Button2Click(Sender: TObject);
  
private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;
var
  Form1: TForm1;
implementation
uses printers, Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
   PrinterSetupDialog1.Execute;
//选择输出的打印机以及其他打印控制选项
end;
procedure MemoPrinter(Memo:TMemo;TitleStr:
string
=
'无标题');
var
Left:Integer;
Top:Integer;
 i,j,x,y : integer;  
//PageHeight,
PagesStr:
String;
posX,posY,Posx1,posY1:Integer;
PrintDialog1:TPrintDialog;
begin
    Left
:=
500;
    Top
:=
800;
    y
:= Top;
// 40
    x
:= Left;
// 80
    j:=1;
  PrintDialog1
:=TPrintDialog.Create(Application);
  
if  PrintDialog1.Execute
then
    
With Printer
do
    
begin
      BeginDoc;
// 另存的打印的文件名 如何实现  默认为 .jnt
      Form2.Show;
      Canvas.Font
:=Memo.Font;
     
//-------------------------------------------------------------------------
     
//打印文件名的标题
     
// TitleStr:='无标题';
      posx
:=(PageWidth
div
2)
- Length(TitleStr)
*
50 ;
//x+1800;
      posy
:= (PageHeight
*
6)
div
100;
      
//第N页的标题
      PagesStr
:=Format(
'第 %d 页',[Printer.PageNumber]);
      posX1
:=(PageWidth
div
2)
- Length(PagesStr)
*
50;
      posY1
:=(PageHeight
*
92)
div
100;
     
//-------------------------------------------------------------------------
      
for i
:=
0
to Memo.Lines.Count
-
1
do
      
begin
        Canvas.TextOut(x,y,Memo.Lines[i]);   
//TextOut(Left,Top,string);
        y
:= y
+ Memo.Font.Size
*
10;          
//Memo.Font.Size*10为行间距 第1行与第2行的间距,2和3,3与4,...
        
if(y
> PageHeight
- Top)
then
          
begin
            Canvas.TextOut(posx,posy,TitleStr);
            
for j
:=
1
to Printer.PageNumber
do
            
begin
                PagesStr
:= Format(
'第 %d 页',[j]);
                Canvas.TextOut(posX1,posY1,PagesStr);
                Application.ProcessMessages;
                Form2.Label1.Caption
:=System.Concat(
' 正在打印',#
13#
10,TitleStr,#
13#
10,Format(
'第 %d 页',[j]));
                
if Form2.Tag
=
1
then
                
begin
                  Abort;
                  Exit;
                
end;
            
end;
            NewPage;
            y
:= Top;
          
end;
      
end;
        Canvas.TextOut( posX, posY, TitleStr );
        Canvas.TextOut( posX1,posY1,Format(
'第 %d 页',[j]) );
        Form2.Close;
        Form1.Label1.Caption
:=System.Concat(
' 正在打印',#
13#
10,TitleStr,#
13#
10,Format(
'第 %d 页',[j]));
      EndDoc;
     
// Form1.Caption:= Format('x = %d y = %d Width = %d Height = %d ',[x,y,PageWidth,Pageheight]);
    
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
    MemoPrinter(Memo1,
'Hello Roman');
end;
end.
 
 
 

unit Unit2;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
  TForm2
=
class(TForm)
    Label1: TLabel;
    Button1: TButton;
    
procedure Button1Click(Sender: TObject);
  
private
    
{ Private declarations }
  
public
    
{ Public declarations }
  
end;
var
  Form2: TForm2;
implementation
{$R *.dfm}
uses Unit1;
procedure TForm2.Button1Click(Sender: TObject);
begin
    Tag
:=
1;
    Close;
end;
end.
 
 
 
 

附件列表

 

转载于:https://www.cnblogs.com/xe2011/p/3374229.html

你可能感兴趣的文章
原子变量的性能问题
查看>>
Sybase PowerDesigner 15.0 完美版+特别文件
查看>>
快速傅立叶之二
查看>>
cetos 6.3 安装 apache+mysql+php
查看>>
js编写简单的贪吃蛇游戏
查看>>
2018/12/01 一个64位操作系统的实现 第四章 导入kernel.bin(4)
查看>>
如何在windows xp professional安装iis的解决方法
查看>>
抽象类和接口
查看>>
使用ASP.NET Atlas AutoComplete Behavior或AutoComplete Extender实现自动完成功能(下)
查看>>
golang 常见疑惑总结
查看>>
8大你不得不知的Android调试工具
查看>>
pc端元素拖拽
查看>>
Sublime Text3使用Package Control 报错There Are No Packages Available For Installation
查看>>
判断连通图是否有环(并查集)
查看>>
汽车之家面试题2016
查看>>
POJ-数据结构-优先队列模板
查看>>
【HAOI2006】旅行(并查集暴力)
查看>>
css实现文本超出部分省略号显示
查看>>
留言板
查看>>
vue-router组件状态刷新消失的问题
查看>>