如何调用对话框来手动设置打印机选项?
我正在使用 WPF,需要让用户设置一些与打印相关的选项,例如打印机和打印机属性(例如纸盒、横向/纵向、双面打印等)。 我知道 PrintDialog 类可以获取 PrintQueue 和 PrintTicket 对象。 但是我需要创建自定义解决方案并且无法显示 PrintDialog。 我设法获取可用的 PrintQueue 对象并让用户选择打印机。 我正在努力解决打印机属性问题。 我的问题是:如何显示用户可以在其中为选定的 PrintQueue 设置打印机属性的对话框(当用户单击 WPF PrintDialog 中的“属性”按钮时显示的对话框)。
I'm using WPF and need to let users set some print related options like printer and printer properties (e.g. papertray, landscape/portrait, duplex, etc). I'm aware of the PrintDialog class to get a PrintQueue and PrintTicket object. However I need to create I custom solution and can not show the PrintDialog.
I manage to get the available PrintQueue objects and let users select a printer. I'm struggling with the printer properties.
My question is: how can I show the dialog in which a user can set the printer properties for the selected PrintQueue (the dialog that is shown when a user clicks on the Properties button in the WPF PrintDialog).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现以下代码此处(减去
Window_Loaded
事件)。 我测试了它,它似乎很有魅力。 显然,在显示对话框之前,您必须在PrinterSettings
对象中设置打印机名称。希望这对您有用:
The following code was found here (minus the
Window_Loaded
event). I tested it and it seems to work like a charm. Obviously you'll have to set the printer name in thePrinterSettings
object before displaying the dialog.Hope this works for you:
如果您以 x86 编译为目标并从 x64 机器运行,则 Pwninstein 的代码将无法工作:分配
devModeData
时,DocumentPropreties
将始终失败并返回sizeNeeded< /code> 为 -1,
LastError
代码为 13。要解决此问题,请确保您以 AnyCPU 为目标,或者仅更改对
DocumentPropreties 的调用code> 改为以下内容:
使用
IntPtr.Zero
而不是指向 DevMode 结构的正确指针看起来是错误的,但对 DocumentProperties 的第一次调用不会尝试修改该位置的内存。 调用返回的唯一数据是存储表示打印驱动程序内部参数的设备模式数据所需的内存大小。参考:
If you target x86 compilation and run from a x64 machine, the code from Pwninstein will not work: when allocating
devModeData
,DocumentPropreties
will always fail and returns asizeNeeded
of -1, with aLastError
code 13.To solve the problem, either make sure you target AnyCPU or just change the call to
DocumentPropreties
to the following:Using
IntPtr.Zero
instead of a proper pointer to a DevMode structure looks wrong, but that first call to DocumentProperties does not attempt to modify the memory at that position. The only data returned by the call is the memory size needed to store the device mode data that represents the internal parameters of the print driver.Reference: