Results 1 to 5 of 5

Thread: Good ol' Printer.hDC

  1. #1

    Thread Starter
    Addicted Member cbond's Avatar
    Join Date
    Apr 2001
    Location
    AZ - USA
    Posts
    148

    Good ol' Printer.hDC

    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

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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!

  3. #3

    Thread Starter
    Addicted Member cbond's Avatar
    Join Date
    Apr 2001
    Location
    AZ - USA
    Posts
    148

    Ratts!

    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.

  4. #4

    Thread Starter
    Addicted Member cbond's Avatar
    Join Date
    Apr 2001
    Location
    AZ - USA
    Posts
    148

    Thanks Slow_Learner

    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.

  5. #5
    New Member
    Join Date
    Jun 2003
    Posts
    1

    Smile

    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.
    Last edited by esskay; Jun 7th, 2003 at 10:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width