views:

393

answers:

2

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?

+1  A: 

You can get one out of the Graphics object returned by PrinterSettings.CreateMeasurementGraphics(). Use the Graphics.GetHdc() method. Don't forget ReleaseHdc() after printing.

Hans Passant
When I created a new `PrinterSettings` object, it was actually initialized with the values from the compatibility `Printer` object that I had set values on before. This is therefore in effect the same as calling `Printer.hdc`! Thanks a lot!
awe
+1  A: 

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.

xpda