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 62
| Private Sub GridToPrint_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs) Handles GridToPrint.PrintPage
e.Graphics.PageUnit = GraphicsUnit.Millimeter
'e.Graphics.FillRectangle(Brushes.Gray, 0, 0, 200, 200)
PrintString(e, "Test Print", New Font("Arial", 25, FontStyle.Bold), Brushes.Black, 5, 10, 0)
PrintString(e, InvoiceNumber, New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 5, 25, 0)
PrintString(e, Format(InvoiceDate, "dd/MM/yyyy"), New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 5, 40, 0)
PrintString(e, "Facture client", New Font("Arial", 25, FontStyle.Bold), Brushes.Black, 5, 60, 0)
Dim bmp As Bitmap = New Bitmap(My.Resources.Resource1.Logo_Infotec___Copie)
Dim imageWidth As Integer, imageHeight As Integer
imageWidth = CInt(bmp.Width / 16)
imageHeight = CInt(bmp.Height / 16)
e.Graphics.DrawImage(bmp, 5, 150, imageWidth, imageHeight)
e.HasMorePages = False
'DrawAngledText(e.Graphics, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, "COPY", 5, 70, 20, 5)
'CurveText(e.Graphics, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, "COPY", 5, 70, 20)
End Sub
Public Sub DrawAngledText(ByVal gr As Graphics, ByVal _
the_font As Font, ByVal the_brush As Brush, ByVal txt _
As String, ByVal x As Integer, ByVal y As Integer, _
ByVal angle_degrees As Single, ByVal y_scale As Single)
' Translate the point to the origin.
gr.TranslateTransform(-x, -y, _
Drawing2D.MatrixOrder.Append)
' Rotate through the angle.
gr.RotateTransform(angle_degrees, _
Drawing2D.MatrixOrder.Append)
' Scale vertically by a factor of Tan(angle).
Dim angle_radians As Double = angle_degrees * Math.PI / 180
gr.ScaleTransform(1, y_scale, _
Drawing2D.MatrixOrder.Append)
' Find the inverse angle and rotate back.
angle_radians = Math.Atan(y_scale * Math.Tan(angle_radians))
angle_degrees = CSng(angle_radians * 180 / Math.PI)
gr.RotateTransform(-angle_degrees, _
Drawing2D.MatrixOrder.Append)
' Translate the origin back to the point.
gr.TranslateTransform(x, y, _
Drawing2D.MatrixOrder.Append)
' Draw the text.
gr.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
gr.DrawString(txt, the_font, the_brush, x, y)
End Sub
Private Sub PrintString(ByVal e As PrintPageEventArgs, ByVal Value As String, ByVal PrintFont As Font, ByVal ForeColor As Brush, ByVal X As Single, ByVal Y As Single, ByVal Align As Byte)
e.Graphics.PageUnit = GraphicsUnit.Millimeter
Dim TextAlign As New StringFormat
Select Case Align
Case 0
TextAlign.Alignment = StringAlignment.Near
Case 1
TextAlign.Alignment = StringAlignment.Far
Case 2
TextAlign.Alignment = StringAlignment.Center
End Select
e.Graphics.DrawString(Value, PrintFont, ForeColor, X, Y, TextAlign)
End Sub |
Partager