VB.net HasMorePages循环

时间:2015-12-24 03:02:48

标签: .net vb.net

所以,我正在尝试制作一个从访问数据库打印页面的程序 我创造了evrything和evrything工作得很好,比我发现我需要打印多个页面,在研究了我的HasMorePages循环之后,我想到了并尝试了很多教程,但它并不顺利 我做的是这个

  Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim Fontt As Font = New Drawing.Font("Time New Roman", 10)
    Dim Font3 As Font = New Drawing.Font("Time New Roman", 12, FontStyle.Bold)
    Dim Typp As Font = New Drawing.Font("Time New Roman", 30)
    Dim Cred As Font = New Drawing.Font("Time New Roman", 20)
    Dim Font2 As Font = New Drawing.Font("Time New Roman", 10, FontStyle.Bold)


    If NumOrdre.Text = "Numero" Then
        R = 170
        TC = Nothing
        TA = Nothing
        C = Nothing
        x = Nothing
        L = Nothing
        D = Nothing
        F = Nothing
        MT = Nothing
        Q = Nothing
        PR = Nothing
        M = Nothing
        NC = Nothing
        Dim p As Integer
        For i = 0 To ds.Tables(2).Rows.Count - 1
            If Val(ComboBox1.Text) = Val(ds.Tables(2).Rows(i)("ID")) Then
                p = i
                Exit For
            End If
        Next
        x = ds.Tables(2).Rows(p)("Client")
        T = ds.Tables(2).Rows(p)("Datee")
        NC = ds.Tables(2).Rows(p)("NumDoc")


        F = "Bon De Livraison"


        For Each row As DataRow In ds.Tables(1).Rows

            If (R > e.MarginBounds.Bottom - 30) Then
                R = 20
                e.HasMorePages = True

                Exit Sub
            Else
                e.HasMorePages = False
            End If










            If row.Item("NumDoc") = ds.Tables(2).Rows(p)("NumDoc") And row.Item("ClientFourni") = ds.Tables(2).Rows(p)("Client") Then
                R = R + 30
                L = row.Item("Ref")
                Dim p2 As Integer
                For i2 = 0 To ds.Tables("Articles").Rows.Count - 1
                    If L = ds.Tables("Articles").Rows(i2)("RefPerso") Then
                        p2 = i2
                        Exit For
                    End If
                Next

                D = ds.Tables("Articles").Rows(p2)("Dessi")

                Dim p3 As Integer
                For i3 = 0 To ds.Tables(1).Rows.Count - 1
                    If L = ds.Tables(1).Rows(i3)("Ref") And ds.Tables(1).Rows(i3)("NumDoc") = NC And ds.Tables(1).Rows(i3)("ClientFourni") = ds.Tables(2).Rows(p)("Client") Then
                        p3 = i3
                        Exit For
                    End If
                Next
                Dim p4 As Integer
                For i4 = 0 To ds.Tables("Clients").Rows.Count - 1
                    If x = ds.Tables("Clients").Rows(i4)("Nom") Then
                        p4 = i4
                        Exit For
                    End If
                Next
                C = ds.Tables("Clients").Rows(p4)("Credit")


                Q = ds.Tables(1).Rows(p3)("Quant")
                PR = ds.Tables(1).Rows(p3)("PrixVente")

                M = PR * Q
                MT = MT + (PR * Q)

                e.Graphics.DrawString(Q, Fontt, Brushes.Black, 581, R + 5)
                e.Graphics.DrawString(D, Fontt, Brushes.Black, 140, R + 5)
                e.Graphics.DrawString(L, Fontt, Brushes.Black, 32, R + 5)
                e.Graphics.DrawString(PR, Fontt, Brushes.Black, 521, R + 5)
                e.Graphics.DrawString(M, Fontt, Brushes.Black, 650, R + 5)

                e.Graphics.DrawRectangle(Pens.Black, 130, R, 390, 30)
                e.Graphics.DrawRectangle(Pens.Black, 31, R, 99, 30)
                e.Graphics.DrawRectangle(Pens.Black, 520, R, 60, 30)
                e.Graphics.DrawRectangle(Pens.Black, 580, R, 60, 30)
                e.Graphics.DrawRectangle(Pens.Black, 640, R, 100, 30)

            End If


        Next row

        e.Graphics.DrawString("Reférence", Font3, Brushes.Black, 32, 175)
        e.Graphics.DrawRectangle(Pens.Black, 31, 170, 99, 30)
        e.Graphics.DrawString("Total", Font3, Brushes.Black, 650, 175)
        e.Graphics.DrawRectangle(Pens.Black, 640, 170, 100, 30)
        e.Graphics.DrawString("Quant", Font3, Brushes.Black, 581, 175)
        e.Graphics.DrawRectangle(Pens.Black, 580, 170, 60, 30)
        e.Graphics.DrawString("Total", Font3, Brushes.Black, 550, R + 35)
        e.Graphics.DrawRectangle(Pens.Black, 520, R + 30, 120, 30)
        e.Graphics.DrawString(MT, Fontt, Brushes.Black, 650, R + 35)
        e.Graphics.DrawRectangle(Pens.Black, 640, R + 30, 100, 30)
        e.Graphics.DrawString(F, Typp, Brushes.Black, 280, 10)
        e.Graphics.DrawString("Client :", Font3, Brushes.Black, 130, 75)
        e.Graphics.DrawString("Numéro:", Font3, Brushes.Black, 130, 125)
        e.Graphics.DrawString(NC, Fontt, Brushes.Black, 220, 125)
        e.Graphics.DrawString("Date:", Font3, Brushes.Black, 450, 125)
        e.Graphics.DrawString(T, Fontt, Brushes.Black, 530, 125)
        e.Graphics.DrawString(x, Fontt, Brushes.Black, 220, 75)
        e.Graphics.DrawString("Désignations", Font3, Brushes.Black, 140, 175)
        e.Graphics.DrawRectangle(Pens.Black, 130, 170, 390, 30)
        e.Graphics.DrawString("Prix", Font3, Brushes.Black, 531, 175)
        e.Graphics.DrawRectangle(Pens.Black, 520, 170, 60, 30)
        e.Graphics.DrawRectangle(Pens.Black, 120, 120, 600, 30)
        e.Graphics.DrawRectangle(Pens.Black, 120, 70, 600, 30)
        e.Graphics.DrawString("Crédit :", Font3, Brushes.Black, 450, 75)
        e.Graphics.DrawString(C, Font3, Brushes.Black, 530, 75)

    End If





End Sub

我尝试打印时得到的结果是HasMorePages循环不会停止

1 个答案:

答案 0 :(得分:0)

设置有更多页面会告诉vb再次运行整个sub。在您的情况下,您永远不会更改r的值,它始终将其设置为true。

我所做的是在我的所有打印语句中使用一个变量作为y值然后增加该变量的值,直到我到达页面底部(加上页脚边距)然后如果你有更多数据要打印设置更多页面结束