• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphi7之 fastreport本地多台打印机情况下如何选择指定打印机打印 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.首先获取当前本地所有的打印机

单元需要引用\'Printers\' 通过Printer.Printers获取打印机列表,存到配置文件或者是键值对中

2.frxReport.PrintOptions.Printer 打印的时候用取到的打印机名称对这个属性进行赋值就可以了。

 

示例代码:Unit1.pas

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, frxClass;

type
  TForm1 = class(TForm)
    cbb_printers: TComboBox;
    Label1: TLabel;
    frxReport1: TfrxReport;
    btnPrint: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  Printers;

procedure TForm1.FormCreate(Sender: TObject);
begin
  cbb_printers.Items.AddStrings(Printer.Printers);
  if cbb_printers.Items.Count > 0 then
    cbb_printers.ItemIndex := 0;
end;

procedure TForm1.btnPrintClick(Sender: TObject);
var
  print_template: string;
begin
  if cbb_printers.Items.Count = 0 then
  begin
    ShowMessage(\'没有打印机\');
    Exit;
  end;

  print_template := ExtractFilePath(ParamStr(0)) + \'print.fr3\';
  if FileExists(print_template) then
  begin
    frxReport1.LoadFromFile(print_template);
    //frxReport1.DesignReport();
  end
  else
  begin
    //ShowMessage(\'打印模板文件:【\' + print_template + \'】不存在\');
  end;

  frxReport1.PrepareReport();
  frxReport1.PrintOptions.ShowDialog:=false;
  frxReport1.PrintOptions.Printer := cbb_printers.Text;
  //frxReport1.Report.PrintOptions.Printer := cbb_printers.Text;
  frxReport1.print;
end;

end.

  

Unit1.dfm

object Form1: TForm1
  Left = 189
  Top = 220
  Width = 766
  Height = 457
  Caption = \'Form1\'
  Color = clBtnFace
  Font.Charset = GB2312_CHARSET
  Font.Color = clBlue
  Font.Height = -19
  Font.Name = \'微软雅黑\'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 25
  object Label1: TLabel
    Left = 200
    Top = 96
    Width = 114
    Height = 25
    Caption = \'打印机列表:\'
  end
  object cbb_printers: TComboBox
    Left = 200
    Top = 144
    Width = 457
    Height = 33
    ItemHeight = 25
    TabOrder = 0
    Text = \'cbb_printers\'
  end
  object btnPrint: TButton
    Left = 272
    Top = 216
    Width = 161
    Height = 57
    Caption = \'打印\'
    TabOrder = 1
    OnClick = btnPrintClick
  end
  object frxReport1: TfrxReport
    Version = \'4.9.32\'
    DotMatrixReport = False
    IniFile = \'\Software\Fast Reports\'
    PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
    PreviewOptions.Zoom = 1.000000000000000000
    PrintOptions.Printer = \'预设\'
    PrintOptions.PrintOnSheet = 0
    ReportOptions.CreateDate = 44085.749619872690000000
    ReportOptions.LastChange = 44085.749619872690000000
    ScriptLanguage = \'PascalScript\'
    ScriptText.Strings = (
      \'begin\'
      \'\'
      \'end.\')
    Left = 192
    Top = 224
    Datasets = <>
    Variables = <>
    Style = <>
  end
end

 

 

  

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap