1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| Private Sub Command3_Click()
' Load the captured image into a PictureBox and print it
'Picture1.Picture = Clipboard.GetData()
'Picture1.PaintPicture Clipboard.GetData(), 0, 0
Dim myPicture1 As New StdPicture, Border As Integer, Echel As Single
Set myPicture1 = Clipboard.GetData()
Border = Picture1.Width - Picture1.ScaleWidth
Picture1.Cls
Echel = 1 '1.25
Picture1.Height = (ScaleY(myPicture1.Height, vbHimetric, vbPixels) / Echel) + Border
Picture1.Width = (ScaleX(myPicture1.Width, vbHimetric, vbPixels) / Echel) + Border
Me.Width = ScaleX(Picture1.Left + Picture1.Width + Picture1.Left, Me.ScaleMode, vbTwips)
Me.Height = ScaleY(Picture1.Top + Picture1.Height + Picture1.Left + 30, Me.ScaleMode, vbTwips)
Picture1.PaintPicture myPicture1, 0, 0, ScaleX(myPicture1.Width, vbHimetric, vbPixels) / Echel, _
ScaleY(myPicture1.Height, vbHimetric, vbPixels) / Echel, _
0, 0, _
ScaleX(myPicture1.Width, vbHimetric, vbPixels), _
ScaleY(myPicture1.Height, vbHimetric, vbPixels), _
vbSrcCopy
Dim DifH As Integer, DifW As Integer, OldPrinterScaleMode As Integer, OldPrinterSens As Integer
Dim DblMarge As Integer
OldPrinterScaleMode = Printer.ScaleMode
OldPrinterSens = Printer.Orientation
Printer.ScaleMode = vbMillimeters
DblMarge = 30 'mm marge haute + marge basse de l'imprimante
If myPicture1.Width > myPicture1.Height Then
Printer.Orientation = vbPRORLandscape
Else
Printer.Orientation = vbPRORPortrait
End If
DifW = ScaleX(myPicture1.Width, vbHimetric, Printer.ScaleMode) - Printer.ScaleWidth
DifH = ScaleY(myPicture1.Height, vbHimetric, Printer.ScaleMode) - Printer.ScaleHeight
If DifW > DifH Then
Echel = ScaleX(myPicture1.Width, vbHimetric, Printer.ScaleMode) / (Printer.ScaleWidth + DblMarge)
Else
Echel = ScaleY(myPicture1.Height, vbHimetric, Printer.ScaleMode) / (Printer.ScaleHeight + DblMarge)
End If
If ScaleX(myPicture1.Width, vbHimetric, Printer.ScaleMode) < (Printer.ScaleWidth + DblMarge) _
And ScaleY(myPicture1.Height, vbHimetric, Printer.ScaleMode) < (Printer.ScaleHeight + DblMarge) Then
Echel = 1
End If
Printer.PaintPicture myPicture1, 0, 0, ScaleX(myPicture1.Width, vbHimetric, vbPixels) / Echel, _
ScaleY(myPicture1.Height, vbHimetric, vbPixels) / Echel, _
0, 0, _
ScaleX(myPicture1.Width, vbHimetric, vbPixels), _
ScaleY(myPicture1.Height, vbHimetric, vbPixels), _
vbSrcCopy
Printer.EndDoc
Printer.Orientation = OldPrinterSens
Printer.ScaleMode = OldPrinterScaleMode
End Sub |
Partager