I am tyring to print a document using an API tool kit for a Document Imaging system.
The print method of my object has a uses the value of the old Printer.hDC from VB6.
How do I get the printer device contex in .Net?
Thanks
Printable View
I am tyring to print a document using an API tool kit for a Document Imaging system.
The print method of my object has a uses the value of the old Printer.hDC from VB6.
How do I get the printer device contex in .Net?
Thanks
Well this is what the help says:
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vxconPrinterObjectChangesInVisualBasicNET.htm
hDC - No longer necessary. An instance of a PrintDocument component is the equivalent of a device context.
Since the "correct" way to print under .NET involves using PrintDocument.Print, I don't see where it exposes a .GetHDC method (e.g. like the Graphics object does). I dunno!
That's what I found as well.
I was hoping to find a way arround it in order to work with this older API for the software I'm am working with.
Thank you anyway.
Thanks again - I finally decided to get back to this as I've been on other projects.
I finally decided to simply create a vb6 dll to handle the 'obsolete' funtions I need while working with this application's SDK.
There is a solution without having to resort to dll's. I am not sure which imaging package you are using, but if yours is like mine, it requires a render method with a printer.hdc.
Took me a little while to figure it out, but it works pretty well.
First, drag a printdocument from the Windows Forms toolbox to your form.
Add the following code to handle the print page:
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim printerhdc As IntPtr = e.Graphics.GetHdc()
' Do whatever you need to do to get the right image
XYZ.Load file(currentpagenumber)
XYZ.Render(printerhdc.ToInt64, 25, 25, Width, Height)
CurrentPageNumber += 1
If CurrentPageNumber < TotalPageCount Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
e.Graphics.ReleaseHdc(printerhdc)
End Sub
Then do the following:
'Gather all the files you need and put their names in an arraylist.
'Then issue the print command
PrintDocument1.Print
' You've just printed your files
Beats having to make a VB6.dll.
BTW, if you look at the available properties and methods for e.Graphics, you won't see the GetHDC and ReleaseHDC. They are, however, somewhat documented in MSDN.