如何获得打印机 HDC
我有一个用 C++ 编写的 COM 组件,具有打印功能。此打印功能将打印机 hDC 作为参数,其中包括用于打印的所有设置。以前,这是从 VB6 代码调用的,在设置 Printer
对象上的所有内容后,Printer.hdc
将在此处工作。
代码已从 VB6 转换为 VB.NET,我已经弄清楚了我需要做的大部分事情。旧的 Printer 对象可通过 Microsoft.VisualBasic.PowerPacks.Printing.Compability.VB6.Printer 类获得,但此处不支持旧的 hdc 属性。
谁能告诉我如何获得这个hdc? 此 hdc 与 System.Drawing.Printing.PrinterSettings
对象上的 GetHdevmode()
相同吗?
I have a COM component written in C++ that has a Print function. This print function takes the Printer hDC as a parameter that includes all settings to use for the print. Previously, this was called from VB6 code, and Printer.hdc
would work here after setting everything on the Printer
object.
The code was converted from VB6 to VB.NET, and I have figured out most of things that I need to do. The old Printer object is available through the Microsoft.VisualBasic.PowerPacks.Printing.Compability.VB6.Printer
class, but the old hdc
property is not supported here.
Can anyone tell me how to get this hdc?
Is this hdc the same as GetHdevmode()
on a System.Drawing.Printing.PrinterSettings
object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以从 PrinterSettings.CreateMeasurementGraphics() 返回的 Graphics 对象中获取其中之一。使用 Graphics.GetHdc() 方法。打印后不要忘记ReleaseHdc()。
You can get one out of the Graphics object returned by PrinterSettings.CreateMeasurementGraphics(). Use the Graphics.GetHdc() method. Don't forget ReleaseHdc() after printing.
hdc 与 getdevmode 不同,但您可以在 .net 中执行所有操作,而无需使用 hdc。如果使用旧代码可以节省时间,您可以从图形对象中获取 hdc 并按照 nobugz 的答案使用它。但是,如果您有打印机的图形对象,则直接绘制到图形对象并完全跳过 hdc 可能会更简单。
Hdc is not the same as getdevmode, but you can do everything in .net without using hdc. If it saves time using the old code, you can get the hdc from the graphics object and use it as in nobugz's answer. But if you have a graphics object for the printer, it might be simpler to draw directly to the graphics object and skip the hdc altogether.
这是与 Hans 建议的方法类似的方法,但它使用表单控件。如果您无论如何都使用表单控件,这可能是一种更简洁的方法。
将 Windows 窗体工具箱中的
PrintDocument
放置到您的窗体中。然后添加以下代码来处理打印页面(作为示例):
source: http://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC
(来源:http://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC)
Here's a similar approach to the one suggested by Hans but it uses a form control. If you are using a form control anyway, this might be a cleaner approach.
Place a
PrintDocument
from the Windows Forms toolbox to your form.Then add the following code to handle the print page (as an example):
source: http://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC
(source: http://www.vbforums.com/showthread.php?247493-Good-ol-Printer-hDC)