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
|
Option Explicit On
Public Class Form1
' OBJETS SUR LA FORM = 4
' button1
' button2
' PrintPreviewControl
' PrintDocument
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Active la visualisation de l'impression, qui ici n'est pas très utile (pour info)
' Option : on peut passer à l'étape du bouton2 et enlever la visualisation et son objet : PrintPreviewControl
Me.PrintPreviewControl1.Zoom = 0.3
Me.PrintPreviewControl1.Rows = 1 ' une page
Dim PageSetupDialog As New PageSetupDialog()
PageSetupDialog.Document = PrintDocument1
PageSetupDialog.PageSettings.Landscape = True ' paysage
Me.PrintPreviewControl1.Document = Me.PrintDocument1 ' appel procédure objet PrintDocument1
End Sub
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Appel impression papier
Dim PageSetupDialog As New PageSetupDialog()
PageSetupDialog.Document = PrintDocument1
PageSetupDialog.PageSettings.Landscape = True
Me.PrintDocument1.Print() ' appel procédure objet PrintDocument1
End Sub
Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
' impression
Dim bmp As New Bitmap(Me.Width, Me.Height, Imaging.PixelFormat.Format32bppArgb)
Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Width, Me.Height)) ' aire d'impression
e.Graphics.DrawImage(bmp, 10, 10) ' marges
End Sub
End Class |
Partager