Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print picture in vb 6.0

Posted on 2007-04-04
1
Medium Priority
?
1,543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
danaseaman earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

671 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