Private Sub CmdPrint_Click()
Dim xmin As Single
Dim ymin As Single
Dim wid As Single
Dim hgt As Single
Dim aspect As Single
MousePointer = vbHourglass
DoEvents
' ***************************************
' Copy the form's image to the clipboard.
' ***************************************
' Press Alt.
keybd_event VK_MENU, 0, 0, 0
DoEvents
' Press Print Scrn.
keybd_event VK_SNAPSHOT, 1, 0, 0
DoEvents
' Release Alt.
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
DoEvents
' Copy the image into the hidden PictureBox.
HiddenPict.Picture = Clipboard.GetData(vbCFBitmap)
' Print the image.
Printer.Orientation = vbPRORLandscape
If NormalOption.Value Then
' Center the image.
wid = Printer.ScaleX(HiddenPict.ScaleWidth, _
ScaleMode, Printer.ScaleMode)
hgt = Printer.ScaleY(HiddenPict.ScaleHeight, _
ScaleMode, Printer.ScaleMode)
xmin = (Printer.ScaleWidth - wid) / 2
ymin = (Printer.ScaleHeight - hgt) / 2
Else
' Make the image as large as possible
' without distortion.
aspect = HiddenPict.ScaleHeight / _
HiddenPict.ScaleWidth
wid = Printer.ScaleWidth
hgt = Printer.ScaleHeight
If hgt / wid > aspect Then
hgt = aspect * wid
xmin = Printer.ScaleLeft
ymin = (Printer.ScaleHeight - hgt) / 2
Else
wid = hgt / aspect
xmin = (Printer.ScaleWidth - wid) / 2
ymin = Printer.ScaleTop
End If
End If
Printer.PaintPicture HiddenPict.Picture, _
xmin, ymin, wid, hgt
Printer.EndDoc
MousePointer = vbDefault
End Sub
|