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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
Private Sub PrintTest2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintDocument1.DefaultPageSettings.Landscape = True
NumPage = 0
CentrageGrpBox()
End Sub
Private Sub CentrageGrpBox()
' MsgBox("on centre")
GroupBox1.Top = (Me.Height - GroupBox1.Height) \ 2
GroupBox1.Left = (Me.Width - GroupBox1.Width) \ 2
GroupBox1.Location = New Point(GroupBox1.Left)
End Sub
Dim iLefmargin As Integer
Dim iTopmargin As Integer
Dim LargPage As Integer
Dim HautPage As Integer
Dim NumPage As Integer
Dim NbreTotalPage As Integer
Dim LeTitre As String = "Le Titre ici "
Dim LaDate As String = DateTime.Now.ToString("dd/MM/yyyy")
Dim LaSem As String = "Semaine " & "14 " & "Année " & "2021"
Dim MaxHautCont As Integer
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
iLefmargin = e.MarginBounds.Left
iTopmargin = e.MarginBounds.Top
LargPage = e.PageSettings.PaperSize.Width
HautPage = e.PageSettings.PaperSize.Height
Dim StfTitre As StringFormat = New StringFormat()
StfTitre.LineAlignment = StringAlignment.Center
StfTitre.Alignment = StringAlignment.Near
Dim StfSem As StringFormat = New StringFormat()
StfSem.LineAlignment = StringAlignment.Center
StfSem.Alignment = StringAlignment.Center
Dim StfDate As StringFormat = New StringFormat()
StfDate.LineAlignment = StringAlignment.Center
StfDate.Alignment = StringAlignment.Far
Dim FontTitre As Font = New Font("Arial", 15, FontStyle.Bold, GraphicsUnit.Point)
Dim FontSem As Font = New Font("Arial", 15, FontStyle.Bold, GraphicsUnit.Point)
Dim FontDate As Font = New Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)
Dim RectEntete As RectangleF = New RectangleF(5, e.PageBounds.Top + 5, e.PageBounds.Width - 10, 30)
Dim RectPied As RectangleF = New RectangleF(5, e.PageBounds.Height - 35, e.PageBounds.Width - 10, 30)
'en-tête
e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(RectEntete))
e.Graphics.DrawString(LeTitre, FontTitre, Brushes.Black, RectEntete, StfTitre)
e.Graphics.DrawString(LaSem, FontTitre, Brushes.Black, RectEntete, StfSem)
e.Graphics.DrawString(LaDate, FontDate, Brushes.Black, RectEntete, StfDate)
'Contenu
Dim Result As String
Dim FontCont As Font = New Font("Arial", 9, FontStyle.Bold, GraphicsUnit.Point)
Dim Pos As Integer = 40
For I = 1 To 25
Result = I
Dim RectCont As RectangleF = New RectangleF(50, Pos, 500, 30)
e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(RectCont))
e.Graphics.DrawString(Result, FontCont, Brushes.Black, RectCont, StfTitre)
Pos = Pos + 35
Next I
'Pied de page
e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(RectPied))
e.Graphics.DrawString("Page n°" & NumPage & " / " & NbreTotalPage, FontDate, Brushes.Black, RectPied, StfDate)
Catch ex As Exception
MsgBox("Erreur d'impression : " & ex.Message)
End Try
End Sub |
Partager