⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 print.pas

📁 Delphi Component - Chart Fx
💻 PAS
字号:
unit print;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, ChartfxLib_TLB, StdCtrls, Printers;

type
  TForm1 = class(TForm)
    ChartFX1: TChartFX;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
    ChartFX1.Printer.Orientation := ORIENTATION_PORTRAIT;
    ChartFX1.ToolBarObj[0].CommandID := CFX_ID_PRINT;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
    ChartFX1.Printer.Orientation := ORIENTATION_LANDSCAPE;
    ChartFX1.ToolBarObj[0].CommandID := CFX_ID_PRINT;
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
    ChartFX1.Printer.Orientation := ORIENTATION_DEFAULT;
    ChartFX1.ToolBarObj[0].CommandID := CFX_ID_DLGPRINT // Show printer setup dialog before printer
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    ChartFX1.ShowDialog(CDIALOG_PAGESETUP, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
VAR
   sDevice,sDriver,sPort:array[0..255] of Char;
   devMode: THandle;
begin
    If RadioButton3.Checked Then begin // prompt user
        if (PrinterSetupDialog1.Execute) Then begin
           Printer.GetPrinter(PChar(@sDevice),pChar(@sDriver),pChar(@sPort),devMode);
           ChartFX1.Printer.PrinterDriver := String(sDevice)+' ,'+String(sDriver)+' ,'+String(sPort);;
        End;
    End;

    ChartFX1.PrintIt(0, 0);   // Print

    ChartFX1.Printer.PrinterDriver := ''; // Restore
end;

procedure TForm1.Button3Click(Sender: TObject);
VAR
    lLastPoint,nTotPages,nTotPoints: LongInt;
    nPage: Integer;
    bQuit: Boolean;
    s,sPage,sTot: String;
    sDevice,sDriver,sPort:array[0..255] of Char;
    devMode: THandle;
begin
    If RadioButton3.Checked Then begin // prompt user
        if (PrinterSetupDialog1.Execute) Then begin
           Printer.GetPrinter(PChar(@sDevice),pChar(@sDriver),pChar(@sPort),devMode);
           ChartFX1.Printer.PrinterDriver := String(sDevice)+' ,'+String(sDriver)+' ,'+String(sPort);;
        end;
    End;

    // Print one page ata a time
    bQuit := False;
    nPage := 1;
    nTotPoints := ChartFX1.NValues;
    nTotPages := -1;
    While Not bQuit do begin
        lLastPoint := ChartFX1.PrintIt(nPage, nPage); // Print one page at a time
        If (lLastPoint <> 0) And (lLastPoint < nTotPoints) Then begin // Is there more ?
            If nTotPages < 0 Then
                nTotPages := Round(nTotPoints / lLastPoint); // Calculate total
            Str(nTotPages,sTot);
            Str(nPage,sPage);
            s := 'Page ' + sPage + ' of ' + sTot + ' Done.' + Chr(10) + 'Another Page ?';
            if MessageDlg(s,mtConfirmation,[mbYes, mbNo], 0) <> mrYes then
                bQuit := True;
            nPage := nPage + 1; // Next page
        end
        Else
            bQuit := True;
    End;

    ChartFX1.Printer.PrinterDriver := ''; // Restore

end;

procedure TForm1.FormActivate(Sender: TObject);
begin
     ChartFX1.RecalcScale;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -