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

📄 uprint.pas

📁 中式财务栏 表格式录入 运行时设置可显示列、列名、列宽
💻 PAS
字号:
{*******************************************************}
{                                                       }
{       打印                                            }
{                                                       }
{       版权所有 (C) 2008 咏南工作室                    }
{                                                       }
{*******************************************************}

unit uPrint;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, PrnDbgeh, DBGridEh, gridseh;

type
  TFormPrint = class(TForm)
    Panel1: TPanel;
    btnPrint: TBitBtn;
    btnClose: TBitBtn;
    GroupBox1: TGroupBox;
    GroupBox3: TGroupBox;
    btnPreview: TBitBtn;
    PrintDBGridEh1: TPrintDBGridEh;
    LabeledEdit1: TLabeledEdit;
    FontDialog1: TFontDialog;
    LabeledEdit2: TLabeledEdit;
    Button1: TButton;
    LabeledEdit3: TLabeledEdit;
    LabeledEdit4: TLabeledEdit;
    LabeledEdit5: TLabeledEdit;
    GroupBox2: TGroupBox;
    LabeledEdit6: TLabeledEdit;
    Button2: TButton;
    LabeledEdit7: TLabeledEdit;
    LabeledEdit8: TLabeledEdit;
    LabeledEdit9: TLabeledEdit;
    FontDialog2: TFontDialog;
    gbPrintFields: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    seUpMargin: TEdit;
    seLowMargin: TEdit;
    seLeftMargin: TEdit;
    seRightMargin: TEdit;
    bPrinterSetupDialog: TButton;
    PrinterSetupDialog1: TPrinterSetupDialog;
    cbFitWidthToPage: TCheckBox;
    CheckBox1: TCheckBox;
    LabeledEdit10: TLabeledEdit;
    Button3: TButton;
    FontDialog3: TFontDialog;
    Label1: TLabel;
    ComboBox1: TComboBox;
    Label2: TLabel;
    ComboBox2: TComboBox;
    btnPageSetup: TButton;
    PageSetupDialog1: TPageSetupDialog;
    procedure btnCloseClick(Sender: TObject);
    procedure btnPreviewClick(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure bPrinterSetupDialogClick(Sender: TObject);
    procedure cbFitWidthToPageClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure btnPageSetupClick(Sender: TObject);
  private
    { Private declarations }
    FDbgridEh: TDBGridEh;
    procedure SetPrintDBGridEh;
  public
    { Public declarations }
  end;

var
  FormPrint: TFormPrint;

procedure PrintMy(ADBGridEh: TDBGridEh);

implementation

{$R *.dfm}

procedure PrintMy(ADBGridEh: TDBGridEh);
begin
  if FormPrint=nil then
    FormPrint:=TFormPrint.Create(nil);
  FormPrint.FDbgridEh:=ADBGridEh;
  FormPrint.PrintDBGridEh1.DBGridEh:=ADBGridEh;
  FormPrint.ShowModal;
end;

procedure TFormPrint.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFormPrint.btnPreviewClick(Sender: TObject);
begin
  SetPrintDBGridEh;
  PrintDBGridEh1.Preview;
  Close;
end;

procedure TFormPrint.btnPrintClick(Sender: TObject);
begin
  SetPrintDBGridEh;
  PrintDbgridEh1.Print;
  Close;
end;

procedure TFormPrint.Button1Click(Sender: TObject);
begin
  if FontDialog1.Execute then
    LabeledEdit2.Text:=FontDialog1.Font.Name+inttostr(fontdialog1.Font.Size);
end;

procedure TFormPrint.Button2Click(Sender: TObject);
begin
  if FontDialog2.Execute then
    LabeledEdit6.Text:=FontDialog2.Font.Name+inttostr(fontdialog2.Font.Size);
end;

procedure TFormPrint.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
  FormPrint:=nil;
end;

procedure TFormPrint.SetPrintDBGridEh;
begin
  with PrintDBGridEh1.PageHeader do
  begin
    Font.Name:=FontDialog1.Font.Name;
    Font.Size:=FontDialog1.Font.Size;
    LeftText.Text:=LabeledEdit3.Text;
    CenterText.Text:=LabeledEdit4.Text;
    RightText.Text:=LabeledEdit5.Text;
    case ComboBox1.ItemIndex of
      0: LineType:=pcltNon;
      1: LineType:=pcltSingleLine;
      2: LineType:=pcltDoubleLine;
    end;
  end;
  with PrintDBGridEh1.PageFooter do
  begin
    Font.Name:=FontDialog2.Font.Name;
    Font.Size:=FontDialog2.Font.Size;
    LeftText.Text:=LabeledEdit7.Text;
    CenterText.Text:=LabeledEdit8.Text;
    RightText.Text:=LabeledEdit9.Text;
    case ComboBox2.ItemIndex of
      0: LineType:=pcltNon;
      1: LineType:=pcltSingleLine;
      2: LineType:=pcltDoubleLine;
    end;
  end;
  with PrintDBGridEh1.Page do
  begin
    TopMargin:=StrToInt(seUpMargin.Text);
    BottomMargin:=StrToInt(seLowMargin.Text);
    LeftMargin:=StrToInt(seLeftMargin.Text);
    RightMargin:=StrToInt(seRightMargin.Text);
  end;
  PrintDBGridEh1.Title.Text:=LabeledEdit1.Text;
  PrintDBGridEh1.PrintFontName:=FontDialog3.Font.Name;   
end;

procedure TFormPrint.bPrinterSetupDialogClick(Sender: TObject);
begin
  PrinterSetupDialog1.Execute;
end;

procedure TFormPrint.cbFitWidthToPageClick(Sender: TObject);
begin
  if cbFitWidthToPage.Checked then
    PrintDBGridEh1.Options := PrintDBGridEh1.Options+[pghFitGridToPageWidth]
  else
    PrintDBGridEh1.Options := PrintDBGridEh1.Options-[pghFitGridToPageWidth];
end;

procedure TFormPrint.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    PrintDBGridEh1.Options:=PrintDBGridEh1.Options+[pghColored]
  else
    PrintDBGridEh1.Options:=PrintDBGridEh1.Options-[pghColored];
end;

procedure TFormPrint.Button3Click(Sender: TObject);
begin
  if FontDialog3.Execute then
    LabeledEdit10.Text:=FontDialog3.Font.Name;  
end;

procedure TFormPrint.btnPageSetupClick(Sender: TObject);
begin
  PageSetupDialog1.Execute;
end;

end.

⌨️ 快捷键说明

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