使用 Delphi VCL。当用户开始打印作业时,我会显示 TPrintDialog。
理想情况下,打印对话框应该显示用户上次使用的打印机名称、纸张尺寸和方向(我已保存)。但是,虽然我可以将方向传递给打印机并使其显示在对话框中,但我找不到让对话框显示默认打印机和纸张尺寸以外的任何内容的方法。
我可以设计一个看起来像打印对话框的自定义对话框,并以这种方式传递参数,但似乎应该有一种方法将这些参数传递给 TPrintDialog。
谢谢。
斯科特
好的,我不确定从 StackOverflow 的角度来看我是否正确地执行了此操作,如果没有,请原谅。
在 Remy 的帮助下,我已经解决了 VCL 工作的问题,但现在我仍停留在 FMX MacOS 版本上。
使用页面方向,我可以成功设置和获取方向,但它不会影响页面设置对话框中的方向或页面的实际打印方式。
以下是我所拥有的:
function getOrientation: string;
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
result:='';
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMGetOrientation(FPrintInfo.PMPageFormat, @orientation);
FPrintInfo.release;
if (orientation=1) or (orientation=3) then result:='portrait';
if (orientation=2) or (orientation=4) then result:='landscape';
end;
procedure setOrientation (const toSetS:string);
var
FPrintInfo: NSPrintInfo;
orientation: integer;
begin
if toSetS='portrait' then orientation:=1 else orientation:=2;
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMSetOrientation(FPrintInfo.PMPageFormat,orientation,true);
FPrintInfo.release;
end;
谢谢。
TPrintDialog
它本身并不支持您所询问的值。但是,它在内部调用 Win32PrintDlg()
API,可以使用DEVMODE
包含dmOrientation
和dmPaperSize
字段的结构体进行初始化。TPrintDialog
在调用 之前检索fromDEVMODE
,然后如果对话成功,则将结果赋值回。因此,您可以在调用 之前使用 方法来为所需设备提供您自己的方法。TPrinter
PrintDlg()
DEVMODE
TPrinter
TPrinter.SetPrinter()
DEVMODE
TPrintDialog
该
TPrinter.Orientation
属性读取/写入当前分配的dmOrientation
的字段。 没有用于读取/写入字段的属性,但您可以手动执行此操作。TPrinter
DEVMODE
TPrinter
dmPaperSize