Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Print preview


'create a sub that accepts an object to which the display is to go
'use picture object for preview, Printer object for actual printing
'PIcture can be a form that displays, or be on the actual page.
'pre-set the picture scale such that the visible area can display the entire printed page
'such as Picture1.Height = Printer.Height / 6 and PIcture1.Width = Printer.Width / 6 (or whatever scale your chose)

Sub PrintPreview(P As Object )
'in this example print a 4x4 matrix strarting in the same location
Dim R As Single , i As Long , j As Long
P.cls
P.ScaleMode = vbInches
P.ScaleMode = vbInches
R = 0.2   'reduction
For i = 1 To 2
    For j = 1 To 2
       P.PaintPicture Picture1.Picture, 2 + (i - 1) * R * Picture1.ScaleWidth, 4 + (j - 1) * R * Picture1.ScaleWidth, R * Picture1.ScaleWidth, R * Picture1.ScaleHeight
    Next j
Next i
End Sub

'usage (preview)
PrintPreview Picture1

'usage (actual printing)
PrintPreview Printer
Printer.EndDoc