Results 1 to 3 of 3

Thread: Sending a paortion of a form to the Printer?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Brisbane, Qld, Australia
    Posts
    78

    Question Sending a portion of a form to the printer?

    Hi,

    I am trying to get the printer to print a section of a form. The part I am trying to get printed is allin a Frame. Inside the frame is Labels, combo boxes, textboxes, check boxes. I need all the info in this Frame and not just to print the whole form. Anyone have any ideas/code/help?
    Any help is appreciated and thanx in advance.

    Mike

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Add 2 pictureboxed to your form, one called pctSource and one called PctDest

    Set pctSource.Autoredraw to true
    set pctsource.borderstyle to none

    make pctDest invisible and set pctDest.autoredraw to true

    cut and paste your frame into pctSource (make sure it's a child window of pctsource and not just resting on top
    make pctSource just large enough to display the entire contents of the fram and make pctdest the same size.

    Insert the following code into your form

    Code:
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As RasterOpConstants) As Long
    
    
    Private Sub FrameOnPrinter(Left As Single, Top As Single)
    
    Dim lngPicWidth As Long
    Dim lngPicHeight As Long
    
    
    'Calculate Picture Dimensions
    lngPicWidth = ScaleX(pctSource.Width, vbTwips, vbPixels)
    lngPicHeight = ScaleY(pctSource.Height, vbTwips, vbPixels)
    
    'Copy Source picture to dest picture
    BitBlt pctDest.hDc, 0, 0, lngPicWidth, lngPicHeight, pctSource.hDc, 0, 0, vbSrcCopy
    
    'put destination picture on printer.
    pctDest.Picture = pctDest.Image
    Printer.PaintPicture pctDest.Picture, Left, Top
    
    End Sub
    FrameOnPrinter will draw your frame onto the printer object for you, I've left the rest of the print handling to you.

    Hope this helps

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Try this
    Code:
        Dim intIndex As Integer
        
        For intIndex = 0 To Me.Controls.Count - 1
            ' Look for all controls outside Frame1 and hide them
            If Me.Controls(intIndex).Container.Name <> "Frame1" Then
                ' But don't hide Frame1 itself
                If Me.Controls(intIndex).Name <> "Frame1" Then
                    Me.Controls(intIndex).Visible = False
                End If
            End If
        Next
        
        Me.PrintForm
        
        For intIndex = 0 To Me.Controls.Count - 1
            Me.Controls(intIndex).Visible = True
        Next

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