Solved

Print picture in vb 6.0

Posted on 2007-04-04
1
1,507 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

10 Experts available now in Live!

Get 1:1 Help Now