Article ID: 175084
Article Last Modified on 8/5/2004
119591 How to Obtain Microsoft Support Files from Online Services
Option Explicit
Const constMaxValue = 32767
Dim lngPrinterWidth As Long, lngPrinterHeight As Long
Dim lngPictureWidth As Long, lngPictureHeight As Long
Dim lngXCoor As Long, lngYCoor As Long
Dim sngWidthRatio As Single, sngHeightRatio As Single
Dim intPageWidth As Integer, intPageHeight As Integer
Dim bytWidthCount As Byte, bytHeightCount As Byte
Private Sub Form_Load()
Command1.Caption = "Load Picture"
Command2.Caption = "Print Single Page"
Command3.Caption = "Print Multiple Pages"
End Sub
Private Sub Command1_Click()
'Opens the common dialog box so you can select a picture file
'to load into the Picture object.
Dim picFile As Picture
CommonDialog1.Filter = "JPEG files|*.jpg|BMP files|*.bmp"
CommonDialog1.ShowOpen
If CommonDialog1.filename <> "" Then
Set picFile = LoadPicture(CommonDialog1.filename)
Set Picture1.Picture = picFile
Form1.Height = Picture1.Height + 1700
Form1.Width = Picture1.Width + 1400
Picture1.Left = 700
Picture1.Top = 700
End If
End Sub
Private Sub Command2_Click()
'Print the picture on a single sheet. Picture object automatically
'adjusts picture size to fit into a single sheet.
Printer.PaintPicture Picture1.Picture, lngXCoor, lngYCoor
Printer.EndDoc
MsgBox "Done Sending Info to Printer"
End Sub
Private Sub Command3_Click()
'Print the picture on multiple sheets.
'Load the dimensions of the image and printer into memory
lngPictureWidth = Picture1.Picture.Width
lngPictureHeight = Picture1.Picture.Height
lngPrinterWidth = Printer.Width
lngPrinterHeight = Printer.Height
'Calculate the ratios
sngWidthRatio = lngPictureWidth / lngPrinterWidth
sngHeightRatio = lngPictureHeight / lngPrinterHeight
'Calculate how many pages are required to print the picture
intPageWidth = constMaxValue - Int(constMaxValue - sngWidthRatio)
intPageHeight = constMaxValue - Int(constMaxValue - _
sngHeightRatio)
For bytWidthCount = 1 To intPageWidth
'Calculate the x-offset
lngXCoor = -lngPrinterWidth * (bytWidthCount - 1)
For bytHeightCount = 1 To intPageHeight
'Calculate the y-offset
lngYCoor = -lngPrinterHeight * (bytHeightCount - 1)
'Use the Paint Picture method to print the picture
Printer.PaintPicture Picture1.Picture, _
lngXCoor, _
lngYCoor, _
lngPictureWidth, _
lngPictureHeight
'start a new page
Printer.NewPage
Next bytHeightCount
Next bytWidthCount
Printer.EndDoc
MsgBox "Done Sending Info to Printer"
End Sub
Additional query words: Prtlgpct
Keywords: kbhowto kbprint kbfile kbsample KB175084