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
Solved

Print picture in vb 6.0

Posted on 2007-04-04
1
1,520 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
to transfer string from C lanaguage to VBA 4 70
MS Date Picker 64 bit 32 bit issue 12 59
SLMGR Switches Are Not Working On KMS Host 3 109
How to Add / Edit Windows Menu 4 67
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

809 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