Hi Martin,
das geht ziemlich einfach:
Du benötigst eine Form und zwei Pictureboxen. Nenne eine Picturebox Picture1, die andere Picture2. Beide Pictureboxen müssen die Autoredraw - Eigenschaft auf True und die Scalemode-Eigenschaft auf Pixcel haben. Im Form_Load-Event setzt Du die Picture2.Visible = False, Picture1 so groß, wie die Printvorschau sein soll. Die Maße so, dass sie den Verhältnissen in etwa der der Papierseite entspricht und mach noch einen schönen Schatten hinten 'dran, wie's Microsoft auch macht .
Alle Ausgaben, die der Drucker machen soll setzt Du in die Picture2! Also ersetze alle Printer - Befehlen durch Picture2, bis auf Printer.EndDoc. Printer.EndDoc entfernen.
jetzt wird's heavy
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _
ByVal dwRop As Long) As Long
Private Sub Form_Load()
Picture2.Visible = False
Picture2.ScaleMode = vbPixels
Printer.ScaleMode = vbPixels
With Picture2
.Width = Printer.ScaleWidth
.Height = Printer.ScaleHeight
End With
End Sub In der Prozedur oder Funktion,die die Printaufbereitung erstellt alle Printer - Befehle durch Picture2 ersetzten (s.o.).
....Picture2.Print "CyberLord"
.....Picture2.Print etcetc
'Printer.EndDoc wurde entfernt!
'Druckvorschau erstellen .....
StretchBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, _
Picture1.ScaleHeight, Picture2.hdc, 0, 0,
Picture2.ScaleWidth, Picture2.ScaleHeight, _
vbSrcCopy Die Eigentlich Printoutroutine musste verlagert werden,
Private Sub cmdPrint_Click()
'Das in Picture2 gepeichert Printbild in den Gerätekontext des Printers
' kopieren ...
BitBlt Printer.hDC,0,0,Printer.ScaleWidth, Printer.Scaleheight, _
Picture2.hDC, 0,0 vbSrcCopy
Printer.Print
Printer.EndDoc
End Sub Voila
cu
Lordchen |