none
Erreur d'impression, nombre de page infini. RRS feed

  • Discussion générale

  • Bonjour a tous,

    Quand je tente d'imprimer plusieurs pages, le nombre de page augmente sans finir.

    Voici le code utiliser.

    Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    
            Dim a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15
            a1 = ComboBox1.SelectedValue.ToString()
            a2 = TextBox4.Text
            a3 = TextBox5.Text
            a4 = TextBox9.Text
            a5 = CommisName.Text
            a6 = TextBox3.Text
            a7 = DateTimePicker1.Value.ToString()
            a8 = TaxLab1.Text
            a9 = TaxLab2.Text
            a10 = Label14.Text
            a11 = Label15.Text
            a12 = TaxTex1.Text
            a13 = TaxTex2.Text
            a14 = TextBox1.Text
            a15 = TextBox6.Text
    
    
    
            Dim blackPen As New Pen(Color.Black, 1)
            Dim drawFormat As New StringFormat
            drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft
    
            With e
    
                'Client/Facture
                .Graphics.DrawString("Adresse de facturation:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 60, 180)
                .Graphics.DrawString(a1, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 60, 200)
                .Graphics.DrawString(a2, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 60, 220)
                .Graphics.DrawString("Téléphone:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 60, 300)
                .Graphics.DrawString(a3, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 160, 300)
                .Graphics.DrawString("Cellulaire:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 60, 320)
                .Graphics.DrawString(a4, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 160, 320)
    
                'Commis/#Facture/Date/Etc.
                .Graphics.DrawString("Commis:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 600, 180)
                .Graphics.DrawString(a5, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 600, 200)
                .Graphics.DrawString("Date:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 600, 220)
                .Graphics.DrawString(a7, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 600, 240)
                .Graphics.DrawString("Facture:", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 600, 260)
                .Graphics.DrawString("#" & a6, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 680, 260)
    
                'form row facture
                .Graphics.DrawLine(blackPen, 60, 400, 800, 400) 'ligne haut
                .Graphics.DrawLine(blackPen, 60, 400, 60, 890) 'ligne gauche
                .Graphics.DrawLine(blackPen, 800, 400, 800, 890) 'ligne droite
                .Graphics.DrawLine(blackPen, 60, 890, 800, 890) 'ligne bas
                .Graphics.DrawLine(blackPen, 60, 440, 800, 440) 'ligne 2em haut
                .Graphics.DrawLine(blackPen, 120, 400, 120, 890) 'ligne 1
                .Graphics.DrawLine(blackPen, 600, 400, 600, 890) 'ligne 2
                .Graphics.DrawLine(blackPen, 700, 400, 700, 890) 'ligne 3
                .Graphics.DrawString("Qté", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 65, 410)
                .Graphics.DrawString("Article(s)", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 125, 410)
                .Graphics.DrawString("Prix", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 605, 410)
                .Graphics.DrawString("Total", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 705, 410)
    
                'Total/Tax
                .Graphics.DrawString(a14, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 700, 910)
                .Graphics.DrawString(a12, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 700, 930)
                .Graphics.DrawString(a13, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 700, 950)
                .Graphics.DrawString(a15, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 700, 970)
    
                .Graphics.DrawString("Total HT", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 910)
                .Graphics.DrawString(a8, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 930)
                .Graphics.DrawString(a9, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 950)
                .Graphics.DrawString("Total TTC", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 970)
    
                .Graphics.DrawString(a10, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 930, drawFormat)
                .Graphics.DrawString(a11, New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 590, 950, drawFormat)
    
    
    
            End With
    
            Dim cunt = dataTable1.Rows.Count.ToString()
    
            Dim cunt2 = 890
    
            For i = 0 To cunt - 1
                If cunt2 < e.MarginBounds.Bottom Then
                    If i <= 15 Then
                        Dim b1 = dataTable1.Rows(i)(2).ToString()
                        Dim b2 = dataTable1.Rows(i)(4).ToString()
                        Dim b3 = dataTable1.Rows(i)(5).ToString()
                        Dim b4 = dataTable1.Rows(i)(7).ToString()
    
                        Dim b5 As Integer = 450 + i * 30
                        Dim b6 As Integer = 470 + i * 30
    
                        e.Graphics.DrawString(b1, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 65, b5)
                        e.Graphics.DrawString(b2, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 125, b5)
                        e.Graphics.DrawString(b3, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 605, b5)
                        e.Graphics.DrawString(b4, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 705, b5)
                        e.Graphics.DrawLine(blackPen, 60, b6, 800, b6) 'ligne bas
    
                    ElseIf i > 15 Then
    
                        Dim b1 = dataTable1.Rows(i)(2).ToString()
                        Dim b2 = dataTable1.Rows(i)(4).ToString()
                        Dim b3 = dataTable1.Rows(i)(5).ToString()
                        Dim b4 = dataTable1.Rows(i)(7).ToString()
    
                        Dim b5 As Integer = 450 + i * 30
                        Dim b6 As Integer = 470 + i * 30
                        Dim b7 As Integer = 400 + i * 30
                        Dim b8 As Integer = 890 + i * 30
    
                        e.Graphics.DrawString(b1, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 65, b5)
                        e.Graphics.DrawString(b2, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 125, b5)
                        e.Graphics.DrawString(b3, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 605, b5)
                        e.Graphics.DrawString(b4, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 705, b5)
                        e.Graphics.DrawLine(blackPen, 60, b6, 800, b6) 'ligne bas
                        e.Graphics.DrawLine(blackPen, 60, b7, 60, b8) 'ligne gauche
                        e.Graphics.DrawLine(blackPen, 800, b7, 800, b8) 'ligne droite
                        e.Graphics.DrawLine(blackPen, 120, b7, 120, b8) 'ligne 1
                        e.Graphics.DrawLine(blackPen, 600, b7, 600, b8) 'ligne 2
                        e.Graphics.DrawLine(blackPen, 700, b7, 700, b8) 'ligne 3
    
                    End If
    
                    cunt2 = cunt2 + i * 30
    
                ElseIf cunt2 < 1612 Then
    
                    e.HasMorePages = True
    
                    Dim b1 = dataTable1.Rows(i)(2).ToString()
                    Dim b2 = dataTable1.Rows(i)(4).ToString()
                    Dim b3 = dataTable1.Rows(i)(5).ToString()
                    Dim b4 = dataTable1.Rows(i)(7).ToString()
    
                    Dim b5 As Integer = 450 + i * 30
                    Dim b6 As Integer = 470 + i * 30
                    Dim b7 As Integer = 400 + i * 30
                    Dim b8 As Integer = 890 + i * 30
    
                    e.Graphics.DrawString(b1, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 65, b5)
                    e.Graphics.DrawString(b2, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 125, b5)
                    e.Graphics.DrawString(b3, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 605, b5)
                    e.Graphics.DrawString(b4, New Font("Arial", 10, FontStyle.Regular), Brushes.Black, 705, b5)
                    e.Graphics.DrawLine(blackPen, 60, b6, 800, b6) 'ligne bas
                    e.Graphics.DrawLine(blackPen, 60, b7, 60, b8) 'ligne gauche
                    e.Graphics.DrawLine(blackPen, 800, b7, 800, b8) 'ligne droite
                    e.Graphics.DrawLine(blackPen, 120, b7, 120, b8) 'ligne 1
                    e.Graphics.DrawLine(blackPen, 600, b7, 600, b8) 'ligne 2
                    e.Graphics.DrawLine(blackPen, 700, b7, 700, b8) 'ligne 3
    
                    cunt2 = cunt2 + i * 30
    
                ElseIf cunt2 >= 1612 Then
    
                    e.HasMorePages = False
                    cunt2 = cunt2 + i * 30
    
                End If
    
    
            Next
    
        End Sub

    Merci de votre aide.

    samedi 28 novembre 2015 14:56

Toutes les réponses

  • Bonjour, Popol85,

    Pouvez-vous activer l'Option Strict On pour déterminer la raison du souci: 
    Option Strict Statement
    Je vous remercie par avance de votre retour.

    Cordialement,
    Teodora


    Votez! Appel à la contribution TechNet Community Support. LE CONTENU EST FOURNI "TEL QUEL" SANS GARANTIE D'AUCUNE SORTE, EXPLICITE OU IMPLICITE. S'il vous plaît n'oubliez pas de "Marquer comme réponse" les réponses qui ont résolu votre problème. C'est une voie commune pour reconnaître ceux qui vous ont aidé, et rend plus facile pour les autres visiteurs de trouver plus tard la résolution.


    mercredi 9 décembre 2015 13:38
    Modérateur