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 61
|
Private Function getBMPToPrint() As Bitmap
Dim Hauteur As Integer = 3508
Dim largeur As Integer = 2480
Dim F As New Font("Arial", 20, FontStyle.Bold) 'Create a font
Dim B As New SolidBrush(Color.Black) 'Create a brush
Dim blackPen As New Pen(Color.Black, 5)
'Create a new bitmap
Dim Bmp As New Bitmap(largeur, Hauteur, Imaging.PixelFormat.Format32bppPArgb)
Dim MyGraphics = Graphics.FromImage(Bmp)
Bmp.SetResolution(300, 300) 'Set the resolution to 300 DPI
MyGraphics = Graphics.FromImage(Bmp) 'Create a graphics object from the bitmap
MyGraphics.Clear(Color.White) 'Paint the canvas white
'Set various modes to higher quality
MyGraphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
MyGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
MyGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
' On crée le cadre
MyGraphics.DrawRectangle(blackPen, 100, 100, largeur - 200, Hauteur - 200)
MyGraphics.DrawRectangle(blackPen, 100, 100, largeur - 200, 200)
MyGraphics.DrawRectangle(blackPen, 100, 100, 500, 200)
MyGraphics.DrawRectangle(blackPen, largeur - 600, 100, 500, 200)
MyGraphics.DrawString("Mon beau document", F, B, (largeur / 2 - 200), 150)
' Insertion des logo
Dim ImagePath As String
ImagePath = Application.StartupPath & "\Image"
Try
MyGraphics.DrawImage(Image.FromFile(ImagePath & "\MonImage.jpg"), New Point(110, 110))
Catch ex As Exception
MessageBox.Show(ImagePath & "\MonImage.jpg non trouvé (" & ex.Message & ")")
End Try
Return Bmp
End Function
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
PrintPreviewDialog1.ShowDialog()
End Sub
' Appelé lors des demande d'impression
Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(getBMPToPrint, 10, 10)
End Sub |
Partager