Solved

Print picture in vb 6.0

Posted on 2007-04-04
1
1,512 Views
Last Modified: 2013-12-25
I have picture1 inside picture2 on the vb 6.0 form. How can I print Picture 2 and also have picture 1 inside it.  I want to make it landscape format. How can I do this.

Thank you in advance.
0
Comment
Question by:Aiysha
1 Comment
 
LVL 22

Accepted Solution

by:
danaseaman earned 500 total points
ID: 18854360
Try this:

'In Form:
Option Explicit

'USAGE - Add a picture box and a command button to a new form.
'        Add various controls to the picture box.
'        Run this code, and press the button to print.
Private Sub Command1_Click()
    PrintPictureBox Picture1, 0, 0
End Sub

'In Module:
Option Explicit

Private Declare Function SendMessage Lib "user32.dll" Alias _
   "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
   ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&    ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20&    ' Draw all owned windows

Public Sub PrintPictureBox(Box As PictureBox, _
                        Optional X As Single = 0, _
                        Optional Y As Single = 0, _
                        Optional bLandscape As Boolean = False)
Dim rv As Long
Dim ar As Boolean
 
    On Error GoTo Exit_Sub
 
    With Box
        'Save ReDraw value
        ar = .AutoRedraw
 
        'Set persistance
        .AutoRedraw = True
   
        'Wake up printer
        Printer.Print
   
        'Draw controls to picture box
        rv = SendMessage(.hwnd, WM_PAINT, .hDC, 0)
        rv = SendMessage(.hwnd, WM_PRINT, .hDC, _
            PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
   
        'Refresh image to picture property
        .Picture = .Image
   
        'Copy picture to Printer
        If bLandscape Then
           Printer.Orientation = vbPRORLandscape
        Else
           Printer.Orientation = vbPRORPortrait
        End If
        Printer.PaintPicture .Picture, X, Y
        Printer.EndDoc
   
        'Restore backcolor  (Re-load picture if picture was used)
        Box.Line (0, 0)-(.ScaleWidth, .ScaleHeight), .BackColor, BF
   
        'Restore ReDraw
        .AutoRedraw = ar
    End With
 
Exit_Sub:
    If Err.Number Then MsgBox Err.Description, vbOKOnly, "Printer Error!"
 
End Sub


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now