Problème d'impression multi page

joujma5 Messages postés 152 Date d'inscription samedi 11 novembre 2006 Statut Membre Dernière intervention 5 décembre 2014 - 11 nov. 2011 à 19:31
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 - 12 nov. 2011 à 11:56
bonjour,
j'ai procédé par le drawing pour imprimer un état, mais je retrouve un problème lorsque l'impression s'étale sur plus qu'une page, je ne sait pas comment y procédé avec le e.hasmorepage=true, la valeur par la quelle je teste si on doit passer à la page suivante est que le datagridview4.rows.count-1 soit supérieur à 15, voici le code:

 Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim fn As New Font("Arial", 14, FontStyle.Bold, GraphicsUnit.Pixel)
        Dim fn1 As New Font("Arial", 14, FontStyle.Underline, GraphicsUnit.Pixel)
        Dim fn2 As New Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Pixel)

        Dim montantTTC As String
        Dim montantHT As String

        Dim drawFormat As New StringFormat
        drawFormat.Alignment = StringAlignment.Far

        montantTTC = Format(CDbl(Label16.Text), "#,##0.##0")
        montantHT = Format(CDbl(Label15.Text), "#,##0.##0")
        e.Graphics.DrawString("Relevé Client", fn, Brushes.Black, 320, 50)
        e.Graphics.DrawString("M.P :", fn, Brushes.Black, 500, 50)
        e.Graphics.DrawString(Label28.Text, fn, Brushes.Black, 560, 50)
        e.Graphics.DrawString(TextBox5.Text.ToUpper(), fn, Brushes.Black, 320, 100)
        e.Graphics.DrawString(Label27.Text, fn, Brushes.Black, 420, 100)

        e.Graphics.DrawString("Date", fn1, Brushes.Black, 70, 150)
        e.Graphics.DrawString("N° Pièce", fn1, Brushes.Black, 220, 150)
        e.Graphics.DrawString("Montant HT", fn1, Brushes.Black, 370, 150)
        e.Graphics.DrawString("Montant TTC", fn1, Brushes.Black, 540, 150)
        e.Graphics.DrawString("Montant NET", fn1, Brushes.Black, 690, 150)

        Dim i As Integer = 70
        Dim z As Integer = 200

        For x As Integer = 0 To DataGridView4.Rows.Count - 1
            e.Graphics.DrawString(DataGridView4.Rows.Item(x).Cells(0).Value, fn, Brushes.Black, i, z)
            e.Graphics.DrawString(DataGridView4.Rows.Item(x).Cells(1).Value, fn, Brushes.Black, i + 150, z)
            e.Graphics.DrawString(Format(DataGridView4.Rows.Item(x).Cells(2).Value, "#,##0.##0"), fn, Brushes.Black, i + 380, z, drawFormat)
            e.Graphics.DrawString(Format(DataGridView4.Rows.Item(x).Cells(3).Value, "#,##0.##0"), fn, Brushes.Black, i + 550, z, drawFormat)
            e.Graphics.DrawString(DataGridView4.Rows.Item(x).Cells(4).Value, fn, Brushes.Black, i + 700, z, drawFormat)
            i = 70
            z = z + 30
        Next

        Dim montantttc_remise As Double = p.baseC00 + p.baseC18 + p.baseC22 + p.montantC18 + p.montantC22
        Dim net_payer As Double = ((montantttc_remise - CDbl(Label9.Text)) + 0.3)

        e.Graphics.DrawString("Base :", fn1, Brushes.Black, 85, z + 50)
        e.Graphics.DrawString(Format(p.baseC00, "#,##0.##0"), fn, Brushes.Black, 230, z + 50, drawFormat)
        e.Graphics.DrawString("Taux :", fn1, Brushes.Black, 85, z + 70)
        e.Graphics.DrawString("0%", fn, Brushes.Black, 230, z + 70, drawFormat)
        e.Graphics.DrawString("Montant :", fn1, Brushes.Black, 85, z + 90)
        e.Graphics.DrawString("0,000", fn, Brushes.Black, 230, z + 90, drawFormat)
        e.Graphics.DrawString(Format(p.baseC18, "#,##0.##0"), fn, Brushes.Black, 335, z + 50, drawFormat)
        e.Graphics.DrawString("18%", fn, Brushes.Black, 335, z + 70, drawFormat)
        e.Graphics.DrawString(Format(p.montantC18, "#,##0.##0"), fn, Brushes.Black, 335, z + 90, drawFormat)
        e.Graphics.DrawString(Format(p.baseC22, "#,##0.##0"), fn, Brushes.Black, 440, z + 50, drawFormat)
        e.Graphics.DrawString("22.5%", fn, Brushes.Black, 440, z + 70, drawFormat)
        e.Graphics.DrawString(Format(p.montantC22, "#,##0.##0"), fn, Brushes.Black, 440, z + 90, drawFormat)

        e.Graphics.DrawString(Format((p.baseC00 + p.baseC18 + p.baseC22), "#,##0.##0"), fn2, Brushes.Black, 450, z + 10, drawFormat)
        e.Graphics.DrawString(Format((montantttc_remise - p.sommepdtnet), "#,##0.##0"), fn2, Brushes.Black, 620, z + 10, drawFormat)
        e.Graphics.DrawString(p.sommepdtnet, fn2, Brushes.Black, 770, z + 10, drawFormat)

        e.Graphics.DrawString("Total TTC :", fn1, Brushes.Black, 545, z + 50)
        e.Graphics.DrawString(Format(montantttc_remise, "#,##0.##0"), fn, Brushes.Black, 770, z + 50, drawFormat)
        e.Graphics.DrawString("Remise :", fn1, Brushes.Black, 545, z + 70)
        e.Graphics.DrawString(Label9.Text, fn, Brushes.Black, 770, z + 70, drawFormat)
        e.Graphics.DrawString("Timbre :", fn1, Brushes.Black, 545, z + 90)
        e.Graphics.DrawString("0.300", fn, Brushes.Black, 770, z + 90, drawFormat)
        e.Graphics.DrawString("Net à Payer :", fn1, Brushes.Black, 545, z + 110)
        e.Graphics.DrawString(Format(net_payer, "#,##0.##0"), fn, Brushes.Black, 770, z + 110, drawFormat)

        ' There are no more pages.
        e.HasMorePages = False

    End Sub

    Private Function PreparePrintDocument() As PrintDocument
        ' Make the PrintDocument object.
        Dim print_document As New PrintDocument

        ' Install the PrintPage event handler.
        AddHandler print_document.PrintPage, AddressOf Print_PrintPage

        ' Return the object.
        Return print_document
    End Function

1 réponse

ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 6
12 nov. 2011 à 11:56
Bonjour,

Je n'ai pas trop le temps là, voici le code de mon pense bête où on voit comment sauter de page (le visu avant impression est facultatif) :

' IMPRESSION
' Impressuin : texte en portrait ou paysage
' Prévisualisation : OBJET = PrintPreviewControl
Sub Button1_Click(
 i = 0 ' Global affecté à cette seule fonction 
 Me.PrintPreviewControl1.Zoom = 0.75
 Me.PrintPreviewControl1.Rows = 4' nb pages vues en apercu (calcul...)
 Dim PageSetupDialog As New PageSetupDialog()  ' objet = PageSetupDialog
 PageSetupDialog.Document = PrintDocument1
 PageSetupDialog.PageSettings.Landscape True ' paysage (portrait False)
 Me.PrintPreviewControl1.Document = Me.PrintDocument1
End Sub

' Impression logique : OBJET = PrintDocument
Sub Button2_Click(
 i = 0 ' Global affecté à cette seule fonction 
 Dim r As String = MsgBox("Imprimer sur PAPIER", vbQuestion + vbYesNo + 
 vbDefaultButton2)
 If r <> vbYes Then Exit Sub
 Dim PageSetupDialog As New PageSetupDialog() ' objet = PageSetupDialog
 PageSetupDialog.Document = PrintDocument1
 PageSetupDialog.PageSettings.Landscape True ' paysage (portrait False)
 Me.PrintDocument1.Print()
End Sub

' Impression physique (papier)
Sub PrintDocument1_PrintPage(
 Dim police As New Font("Courier New", 12, FontStyle.Regular)
 Dim yPos As Integer = 10 ' pixels
 Do While i < ListBox1.Items.Count
  e.Graphics.DrawString(ListBox1.Items(i), police, Brushes.Black, 10, yPos)
  Select Case i 
   Case 3, 6, 9
     e.HasMorePages = True ' saut de page
      i = i + 1
     Return ' retour saut de page à Me.PrintDocument1.Print()
  End Select
  yPos = yPos + police.GetHeight
  i = i + 1
 Loop
End Sub


Cordialemenjt, Joe.
0