DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: How to print scrolling form in vb6

  1. #1
    Join Date
    Nov 2008
    Posts
    10

    How to print scrolling form in vb6

    I would like to print the contents of an MDI child form that is much larger than the screen size. When I use the statement

    myform.printform

    only the first part of the form is printed (essentially the part that would be captured by a screen capture). Is there any relatively straightforward way to print the entire form, e.g., over multiple pages?

    Thanks in advance for your help.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Not that I'm aware.

    Perhaps doing a printform - scroll - printform - scroll - etc?

  3. #3
    Join Date
    Nov 2008
    Posts
    10
    Hack, Thanks for the suggestion. I tried that approach. Unfortunately the PrintForm method still printed only the top of the form.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Try this for the printing instead of Me.PrintForm
    Code:
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Private Const VK_MENU As Byte = &H12
    Private Const VK_SNAPSHOT As Byte = &H2C
    Private Const KEYEVENTF_KEYUP = &H2
    
    Private Sub PrintTheForm()
    Dim lWidth As Long, lHeight As Long
        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
        If Width > Printer.ScaleWidth Then
            lWidth = Printer.ScaleWidth
            lHeight = (Printer.ScaleWidth / Width) * Height
        Else
            lWidth = Width
            lHeight = Height
        End If
        Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
        Printer.EndDoc
    End Sub
    This actually takes a pictures (or a "snapshot") of what is actually on the screen, so it should capture what is there after you do a scroll.

  5. #5
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Looks like Hack's solved it for you, but i was going to suggest SavePicture(), to save the form's image to a file, and print it. Not sure whether it'd work with an MDI form's child though

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Quote Originally Posted by CptNeutral
    Looks like Hack's solved it for you, but i was going to suggest SavePicture(), to save the form's image to a file, and print it. Not sure whether it'd work with an MDI form's child though
    That isn't a bad idea actually, with one potential "gotcha" and that is that SavePicture, which will save the contents of a picturebox control, is only going to save the contents in a bitmap format. This restricts the size to 1600x1200x24 bits.

    This might not be an issue in this case, but it is something worth noting.

  7. #7
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    I didn't know that, thanks.

  8. #8
    Join Date
    Nov 2008
    Posts
    10
    Both ideas seem to work. Thanks much!

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Great!

    CptNeutral's idea would be a good way to save a picture of the screen at any given point in time.

  10. #10
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Glad to have helped.

Similar Threads

  1. how to embed Oracle's Form and Report into VB6?
    By hmdaud@yahoo.co in forum VB Classic
    Replies: 0
    Last Post: 09-10-2007, 09:08 AM
  2. Print a Form
    By Eugene in forum Java
    Replies: 0
    Last Post: 04-09-2001, 03:54 PM
  3. Stored Procedure (Want looping in Cursor)
    By malikmehmood in forum Database
    Replies: 0
    Last Post: 11-20-2000, 06:12 AM
  4. print form problem
    By crni in forum VB Classic
    Replies: 0
    Last Post: 10-14-2000, 08:37 PM
  5. How to print out a form
    By chong in forum VB Classic
    Replies: 0
    Last Post: 03-30-2000, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center