zoukankan      html  css  js  c++  java
  • Memo打印1

     
     
     
     
     
    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.
     
     
     
     





    附件列表

  • 相关阅读:
    【LeetCode每天一题】Pascal's Triangle(杨辉三角)
    【Redis】持久化
    【LeetCode每天一题】Swap Nodes in Pairs
    【LeetCode每天一题】Reverse String
    [bzoj2152]聪聪可可
    [bzoj3572][Hnoi2014]世界树
    Codeforces Round#409/VK-Cup 2017 Round2
    Educational Codeforces Round#19
    [bzoj4813][Cqoi2017]小Q的棋盘
    [bzoj4236]JOIOJI
  • 原文地址:https://www.cnblogs.com/xe2011/p/3374229.html
Copyright © 2011-2022 走看看