Results 1 to 16 of 16

Thread: Printing ENTIRE form/Picture Box

  1. #1

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Printing ENTIRE form/Picture Box

    Hi all...
    Need to print the entire form to the printer. Mainly I need the contents of a picture box to print. Picture DOES NOT fit onto the screen and has scroll bar navigation. I need to print the entire thing, not just what is visible. I found this:

    Code:
    Private Sub print_Click()
    
    Dim lWidth As Long, lHeight As Long
    
    Me.Hide
    Me.Height = 13080
    Me.Width = 13800
    
    Me.Move 0, 0
    Me.Show
    
    Printer.ScaleWidth = Me.Width
    Printer.ScaleHeight = Me.Height
    
    lWidth = Me.Width
    lHeight = (Printer.ScaleWidth / Me.Width) * Me.Height
    
    Clipboard.Clear
    Call keybd_event(VK_MENU, 0, 0, 0)
    Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    
    DoEvents
    
    Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
    Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
    Printer.Print
    Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
    Printer.EndDoc
    
    End Sub
    ...I only get what is displayed, and sometimes some stuff from my desktop (screen shot?) What am I doing wrong?
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing ENTIRE form/Picture Box

    You are not doing anything wrong...it is doing exactly what you are telling it to do...take a screenshot (i.e., what is visible) and send it to the printer.

  3. #3

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    Hmmm. So how do I dump the entire form to the printer then? Mainly I need the contents of a frame that contains a picturebox.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Printing ENTIRE form/Picture Box

    What's in your picturebox? Image only or some other controls, etc?
    Alternatively you can create some kind of report (DataReport, Crystal Reports, Active Reports, etc) so you can pass data only and print that instead.

  5. #5

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    Quote Originally Posted by RhinoBull View Post
    What's in your picturebox? Image only or some other controls, etc?
    Alternatively you can create some kind of report (DataReport, Crystal Reports, Active Reports, etc) so you can pass data only and print that instead.
    The picture box is in a frame and contains a custom background image for a graph and there are some controls (actually shapes and text) in the frame too that overlay on the picture box to complete the "graph". So what I need is a way to print the entire contents of the frame keeping the same aspect ratio.
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Printing ENTIRE form/Picture Box

    here is an example from microsoft that shows how to print the form or window
    http://support.microsoft.com/default...b;en-us;161299
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Member
    Join Date
    Jun 2010
    Posts
    40

    Re: Printing ENTIRE form/Picture Box

    Call keybd_event(VK_MENU, 0, 0, 0)
    Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
    I get an error: "Sub or Function not defined"

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Printing ENTIRE form/Picture Box

    Those are windows api so you need to declare them:
    Code:
    Option Explicit
    
    Private Const VK_MENU As Long = &H12
    Private Const VK_SNAPSHOT As Long = &H2C
    
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Use declarations as is if you do it in the form or change scope to Public when declaring in the module.

  9. #9
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Printing ENTIRE form/Picture Box

    aa9

    This might help

    Code:
            PB1.Picture = PB1.Image
            ff = "d:\pb1023.bmp"
            SavePicture PB1.Picture, ff
    It will save the contents of your PictureBox (here, named PB1) to a file.
    Natch, change PB name and file name as required.
    I'm not quite sure how to then physically print it.. hopefully you can figure that out ..

    Spoo

  10. #10

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    Quote Originally Posted by westconn1 View Post
    here is an example from microsoft that shows how to print the form or window
    http://support.microsoft.com/default...b;en-us;161299
    Trying to use the printform feature of this code and am having issues.
    I get a runtime error#13 "Type Mismatch" in this function at
    Code:
    Set CreateBitmapPicture = IPic
    Code:
          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          ' CreateBitmapPicture
          '    - Creates a bitmap type Picture object from a bitmap and
          '      palette.
          '
          ' hBmp
          '    - Handle to a bitmap.
          '
          ' hPal
          '    - Handle to a Palette.
          '    - Can be null if the bitmap doesn't use a palette.
          '
          ' Returns
          '    - Returns a Picture object containing the bitmap.
          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          '
          #If Win32 Then
             Public Function CreateBitmapPicture(ByVal hBmp As Long, _
                ByVal hPal As Long) As Picture
    
                Dim r As Long
          #ElseIf Win16 Then
             Public Function CreateBitmapPicture(ByVal hBmp As Integer, _
                ByVal hPal As Integer) As Picture
    
                Dim r As Integer
          #End If
             Dim PIC As PicBmp
             ' IPicture requires a reference to "Standard OLE Types."
             Dim IPic As IPicture
             Dim IID_IDispatch As GUID
    
             ' Fill in with IDispatch Interface ID.
             With IID_IDispatch
                .Data1 = &H20400
                .Data4(0) = &HC0
                .Data4(7) = &H46
             End With
    
             ' Fill Pic with necessary parts.
             With PIC
                .Size = Len(PIC)          ' Length of structure.
                .Type = vbPicTypeBitmap   ' Type of Picture (bitmap).
                .hBmp = hBmp              ' Handle to bitmap.
                .hPal = hPal              ' Handle to palette (may be null).
             End With
    
             ' Create Picture object.
             r = OleCreatePictureIndirect(PIC, IID_IDispatch, 1, IPic)
    
             ' Return the new Picture object.
             Set CreateBitmapPicture = IPic
          End Function
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Printing ENTIRE form/Picture Box

    i created a sample project as described, i do not get any error at that point, and the printout is fine
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    article talks about vb4, this does run in vb6 too right???
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Printing ENTIRE form/Picture Box

    yes i was using vb6, without problem
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    Quote Originally Posted by westconn1 View Post
    yes i was using vb6, without problem
    Code:
      ' IPicture requires a reference to "Standard OLE Types."
             Dim IPic As IPicture
    I always keep getting a type mis-match runtime error. How do I set the "reference to Standard OLE Types" ? Under "Projects > Components"?

    I think I'm doing this right.... I put all that printer code (from that link) into a module (.bas) then the print button on my form does:
    Code:
    Set Picture1.Picture = CaptureForm(Me)
    PrintPictureToFitPage Printer, Picture1.Picture
    Printer.EndDoc
    Last edited by aa9gg; Jul 7th, 2010 at 12:44 PM. Reason: content
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Printing ENTIRE form/Picture Box

    How do I set the "reference to Standard OLE Types" ? Under "Projects > Components"?
    i did not need to, it just worked correctly for me

    can you post a simple, sample project, that demonstrates the error?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    Re: Printing ENTIRE form/Picture Box

    Well I can not get past that type mis-match error. I don't understand why I get it. I found another method, but I'm having issues with it too (http://support.microsoft.com/default...;EN-US;q230502)
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

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