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
| Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim text As String = " Acteurs et actrices sans photo"
Dim Entete As String
Dim printFont As New System.Drawing.Font("Comic sans MS", 10, System.Drawing.FontStyle.Bold)
'Declaration d'une variable "statique" pour pouvoir parcourir le listView en cas des plusieurs pages
Static pos As Int32 = 0
Static NouvellePage As Boolean = True
Dim HauteurTexte As Single = e.Graphics.MeasureString("X", Me.ListView1.Font).Height 'Recuperation d'hauteur du texte
Dim LignePerPage As Int32 = CInt(e.MarginBounds.Height / HauteurTexte) 'Calcul de nombre des lignes par page
Dim XPos, YPos As Single 'Les positions temporaires
YPos = 50 'HauteurTexte
XPos = 0
'Imprime la liste
'For C As Integer = 0 To ListView1.Columns.Count - 1
'Entete = ListView1.Columns(C).Text
'e.Graphics.DrawString(Entete, printFont, System.Drawing.Brushes.Black, 0, 0)
'Next
Entete = " " & ListView1.Columns(0).Text & " " & ListView1.Columns(1).Text
e.Graphics.DrawString(Entete, printFont, System.Drawing.Brushes.Black, 0, 20)
For cmptLig As Int32 = 0 To ListView1.Items.Count - 1
If NouvellePage Then
'imprime en-tête
e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, 0, 0)
NouvellePage = False
End If
If cmptLig > LignePerPage Then
YPos = 50
e.HasMorePages = True
NouvellePage = True
Exit For
ElseIf pos > ListView1.Items.Count - 1 Then
'travail termine
e.HasMorePages = False
pos = 0
Exit For
End If
For clm As Int32 = 0 To ListView1.Columns.Count - 1
e.Graphics.DrawString(ListView1.Items(pos).SubItems(clm).Text, ListView1.Font, Brushes.Black, XPos, YPos) ' New Font("Arial", 15, FontStyle.Regular)
XPos += ListView1.Columns(clm).Width 'la position horisontale
Next
YPos += HauteurTexte
XPos = 0
pos += 1
Next
If e.HasMorePages = False Then pos = 0 'Si il n'y a que une page on met la variable statique a 0
End Sub |
Partager