通过程序设置打印机

  易飞的报表打印方向(横向和纵向)是取自默认打印机的设置,所以你会发现如果系统中没有默认打印机的话易飞是无法设计报表的。有客户反映有的报表格式比较固定(横向),由于操作繁琐故没有必要每次都把纸张的方向从纵向设置为横向。

  我们可以在设计报表ReportViewer元件对这些报表作业时把打印机临时设为横向,待退出处理后再恢复回来。实现代码如下:

Code
public
FChange: Boolean;
。。。。。。
procedure TfrmReportViewer.FormShow(Sender: TObject);
var

ADevice, ADriver, APort:
array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//^_^ 20080911 ADD BY ==start 设置为横向
FChangeProperty :
=
False;

If FReportID
= 'COPR01'
THEN
Begin
{

方法一:用的时候把弹出窗体去掉,直接确认即可
ShellExecute(0, 'OPEN', PChar('D:\Conductor70\C_Dsbin\HP_A4_H.reg'), nil, nil, SW_SHOWNORMAL);
WinExec(PChar('D:\Conductor70\C_Dsbin\HP_A4_H.reg'), 1);
}
//
方法二:
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);

if DeviceHandle = 0 then

begin
Printer.PrinterIndex :
= Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end
;

if DeviceHandle = 0 then

Raise Exception.Create(
'不能初始化打印机!')
else

DevMode :
= GlobalLock(DeviceHandle);

if DeviceHandle <> 0 then

begin
with DevMode^ do
begin
dmFields :
= dmFields or DM_ORIENTATION;
dmOrientation :
=
DMORIENT_LANDSCAPE;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end
;
end
;
FormatChange;
RepaintArea(
0
, ToolBar.Height, VScrollBar.Left, HScrollBar.Top);

FChangeProperty :
=
True;
End;
//^_^ 20080911 ADD BY ==end


inherited;

end
;


procedure TfrmReportViewer.FormClose(Sender: TObject;var
Action: TCloseAction);
var

ADevice, ADriver, APort:
array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//^_^ 20080911 ADD BY ==start 设置为纵向
If FChange THEN
Begin
//
方法一:用时候去掉确认窗
//ShellExecute(0, 'OPEN', PChar('D:\Conductor70\C_Dsbin\HP_A4_L.reg'), nil, nil
, SW_SHOWNORMAL);

//
方法二:
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);

if DeviceHandle = 0 then

begin
Printer.PrinterIndex :
= Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end
;

if DeviceHandle = 0 then

Raise Exception.Create(
'不能初始化打印机!')
else

DevMode :
= GlobalLock(DeviceHandle);

if DeviceHandle <> 0 then

begin
with DevMode^ do
begin
dmFields :
= dmFields or DM_ORIENTATION;
dmOrientation :
=
DMORIENT_PORTRAIT;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end
;
end
;

End;
//^_^ 20080911 ADD BY ==end


WriteTransferDataIni([
is
_ShowSetting]);
Disconnect;
// if ((FReportSource= rs_Leader)or(FReportSource= rs_VarLeader))then

if (FReportSource= rs_Leader) then
Action:
= caFree
else Action:=
caHide;
end;

转载于:https://www.cnblogs.com/safezone/articles/1288921.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值